Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
16cc5372
Commit
16cc5372
authored
22 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Avoid malloc(0) when printing a table of no columns. On some platforms
this returns NULL, which confuses the code.
parent
643dfb78
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/bin/psql/print.c
+29
-18
29 additions, 18 deletions
src/bin/psql/print.c
with
29 additions
and
18 deletions
src/bin/psql/print.c
+
29
−
18
View file @
16cc5372
...
...
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.3
4
2002/1
0/24 01:33:50 momjian
Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.3
5
2002/1
1/01 15:12:19 tgl
Exp $
*/
#include
"postgres_fe.h"
#include
"common.h"
...
...
@@ -212,6 +212,8 @@ print_aligned_text(const char *title, const char *const * headers,
for
(
ptr
=
headers
;
*
ptr
;
ptr
++
)
col_count
++
;
if
(
col_count
>
0
)
{
widths
=
calloc
(
col_count
,
sizeof
(
*
widths
));
if
(
!
widths
)
{
...
...
@@ -225,8 +227,14 @@ print_aligned_text(const char *title, const char *const * headers,
perror
(
"calloc"
);
exit
(
EXIT_FAILURE
);
}
}
else
{
widths
=
NULL
;
head_w
=
NULL
;
}
/* count
rows
*/
/* count
cells (rows * cols)
*/
for
(
ptr
=
cells
;
*
ptr
;
ptr
++
)
cell_count
++
;
...
...
@@ -240,23 +248,25 @@ print_aligned_text(const char *title, const char *const * headers,
}
}
else
cell_w
=
0
;
cell_w
=
NULL
;
/* calc column widths */
for
(
i
=
0
;
i
<
col_count
;
i
++
)
{
if
((
tmp
=
pg_wcswidth
((
unsigned
char
*
)
headers
[
i
],
strlen
(
headers
[
i
])))
>
widths
[
i
])
tmp
=
pg_wcswidth
((
unsigned
char
*
)
headers
[
i
],
strlen
(
headers
[
i
]));
if
(
tmp
>
widths
[
i
])
widths
[
i
]
=
tmp
;
head_w
[
i
]
=
tmp
;
}
for
(
i
=
0
,
ptr
=
cells
;
*
ptr
;
ptr
++
,
i
++
)
{
if
((
tmp
=
pg_wcswidth
((
unsigned
char
*
)
*
ptr
,
strlen
(
*
ptr
)))
>
widths
[
i
%
col_count
])
tmp
=
pg_wcswidth
((
unsigned
char
*
)
*
ptr
,
strlen
(
*
ptr
));
if
(
tmp
>
widths
[
i
%
col_count
])
widths
[
i
%
col_count
]
=
tmp
;
cell_w
[
i
]
=
tmp
;
}
if
(
opt_border
==
0
)
total_w
=
col_count
-
1
;
else
if
(
opt_border
==
1
)
...
...
@@ -272,10 +282,11 @@ print_aligned_text(const char *title, const char *const * headers,
{
int
tlen
;
if
((
unsigned
int
)
(
tlen
=
pg_wcswidth
((
unsigned
char
*
)
title
,
strlen
(
title
)))
>=
total_w
)
tlen
=
pg_wcswidth
((
unsigned
char
*
)
title
,
strlen
(
title
));
if
(
tlen
>=
(
int
)
total_w
)
fprintf
(
fout
,
"%s
\n
"
,
title
);
else
fprintf
(
fout
,
"%-*s%s
\n
"
,
(
int
)
(
total_w
-
tlen
)
/
2
,
""
,
title
);
fprintf
(
fout
,
"%-*s%s
\n
"
,
(
(
int
)
total_w
-
tlen
)
/
2
,
""
,
title
);
}
/* print headers */
...
...
@@ -330,7 +341,7 @@ print_aligned_text(const char *title, const char *const * headers,
}
/* content */
if
(
opt_align
[
(
i
)
%
col_count
]
==
'r'
)
if
(
opt_align
[
i
%
col_count
]
==
'r'
)
{
fprintf
(
fout
,
"%*s%s"
,
widths
[
i
%
col_count
]
-
cell_w
[
i
],
""
,
cells
[
i
]);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment