Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c26497

Browse files
committed
Fix some signed-vs-unsigned-int issues; make print_aligned_vertical
safe for zero-column tables.
1 parenteb5e4c5 commit9c26497

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

‎src/bin/psql/print.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.36 2003/03/18 22:15:44 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.37 2003/04/0415:48:38 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -283,13 +283,11 @@ print_aligned_text(const char *title, const char *const * headers,
283283
/* print title */
284284
if (title&& !opt_barebones)
285285
{
286-
inttlen;
287-
288-
tlen=pg_wcswidth((unsignedchar*)title,strlen(title),encoding);
289-
if (tlen >= (int)total_w)
286+
tmp=pg_wcswidth((unsignedchar*)title,strlen(title),encoding);
287+
if (tmp >=total_w)
290288
fprintf(fout,"%s\n",title);
291289
else
292-
fprintf(fout,"%-*s%s\n", ((int)total_w-tlen) /2,"",title);
290+
fprintf(fout,"%-*s%s\n", (total_w-tmp) /2,"",title);
293291
}
294292

295293
/* print headers */
@@ -305,7 +303,7 @@ print_aligned_text(const char *title, const char *const * headers,
305303

306304
for (i=0;i<col_count;i++)
307305
{
308-
intnbspace;
306+
unsignedintnbspace;
309307

310308
nbspace=widths[i]-head_w[i];
311309

@@ -420,18 +418,27 @@ print_aligned_vertical(const char *title, const char *const * headers,
420418
/* count headers and find longest one */
421419
for (ptr=headers;*ptr;ptr++)
422420
col_count++;
423-
head_w=calloc(col_count,sizeof(*head_w));
424-
if (!head_w)
421+
if (col_count>0)
425422
{
426-
perror("calloc");
427-
exit(EXIT_FAILURE);
423+
head_w=calloc(col_count,sizeof(*head_w));
424+
if (!head_w)
425+
{
426+
perror("calloc");
427+
exit(EXIT_FAILURE);
428+
}
428429
}
430+
else
431+
head_w=NULL;
432+
429433
for (i=0;i<col_count;i++)
430434
{
431-
if ((tmp=pg_wcswidth((unsignedchar*)headers[i],strlen(headers[i]),encoding))>hwidth)
435+
tmp=pg_wcswidth((unsignedchar*)headers[i],strlen(headers[i]),encoding);
436+
if (tmp>hwidth)
432437
hwidth=tmp;
433438
head_w[i]=tmp;
434439
}
440+
441+
/* Count cells, find their lengths */
435442
for (ptr=cells;*ptr;ptr++)
436443
cell_count++;
437444

@@ -445,12 +452,13 @@ print_aligned_vertical(const char *title, const char *const * headers,
445452
}
446453
}
447454
else
448-
cell_w=0;
455+
cell_w=NULL;
449456

450457
/* find longest data cell */
451458
for (i=0,ptr=cells;*ptr;ptr++,i++)
452459
{
453-
if ((tmp=pg_wcswidth((unsignedchar*)*ptr,strlen(*ptr),encoding))>dwidth)
460+
tmp=pg_wcswidth((unsignedchar*)*ptr,strlen(*ptr),encoding);
461+
if (tmp>dwidth)
454462
dwidth=tmp;
455463
cell_w[i]=tmp;
456464
}
@@ -480,7 +488,6 @@ print_aligned_vertical(const char *title, const char *const * headers,
480488
if (opt_border==2)
481489
strcat(divider,"-+");
482490

483-
484491
/* print records */
485492
for (i=0,ptr=cells;*ptr;i++,ptr++)
486493
{
@@ -544,7 +551,6 @@ print_aligned_vertical(const char *title, const char *const * headers,
544551
if (opt_border==2)
545552
fprintf(fout,"%s\n",divider);
546553

547-
548554
/* print footers */
549555

550556
if (!opt_barebones&&footers&&*footers)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp