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

Commit9bf2ac2

Browse files
committed
Clean up signedness warnings and 64-bit bugs in recent psql printing
patch. Martijn van Oosterhout and Tom Lane
1 parentfc9c20e commit9bf2ac2

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

‎src/bin/psql/mbprint.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.19 2006/02/1000:39:04 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.20 2006/02/1022:29:06 tgl Exp $
77
*/
88

99
#include"postgres_fe.h"
@@ -158,11 +158,11 @@ pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding)
158158
{
159159
intchlen,chwidth;
160160

161-
chlen=PQmblen(pwcs,encoding);
161+
chlen=PQmblen((constchar*)pwcs,encoding);
162162
if (chlen>len)
163163
break;/* Invalid string */
164164

165-
chwidth=PQdsplen(pwcs,encoding);
165+
chwidth=PQdsplen((constchar*)pwcs,encoding);
166166

167167
if (chwidth>0)
168168
width+=chwidth;
@@ -191,10 +191,10 @@ pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *result_width,
191191

192192
for (;*pwcs&&len>0;pwcs+=chlen)
193193
{
194-
chlen=PQmblen(pwcs,encoding);
194+
chlen=PQmblen((char*)pwcs,encoding);
195195
if (len< (size_t)chlen)
196196
break;
197-
w=PQdsplen(pwcs,encoding);
197+
w=PQdsplen((char*)pwcs,encoding);
198198

199199
if (chlen==1)/* ASCII char */
200200
{
@@ -256,15 +256,14 @@ pg_wcsformat(unsigned char *pwcs, size_t len, int encoding,
256256
intw,
257257
chlen=0;
258258
intlinewidth=0;
259-
260-
char*ptr=lines->ptr;/* Pointer to data area */
259+
unsignedchar*ptr=lines->ptr;/* Pointer to data area */
261260

262261
for (;*pwcs&&len>0;pwcs+=chlen)
263262
{
264-
chlen=PQmblen(pwcs,encoding);
263+
chlen=PQmblen((char*)pwcs,encoding);
265264
if (len< (size_t)chlen)
266265
break;
267-
w=PQdsplen(pwcs,encoding);
266+
w=PQdsplen((char*)pwcs,encoding);
268267

269268
if (chlen==1)/* single byte char char */
270269
{
@@ -282,13 +281,13 @@ pg_wcsformat(unsigned char *pwcs, size_t len, int encoding,
282281
}
283282
elseif (*pwcs=='\r')/* Linefeed */
284283
{
285-
strcpy(ptr,"\\r");
284+
strcpy((char*)ptr,"\\r");
286285
linewidth+=2;
287286
ptr+=2;
288287
}
289288
elseif (w <=0)/* Other control char */
290289
{
291-
sprintf(ptr,"\\x%02X",*pwcs);
290+
sprintf((char*)ptr,"\\x%02X",*pwcs);
292291
linewidth+=4;
293292
ptr+=4;
294293
}
@@ -301,13 +300,13 @@ pg_wcsformat(unsigned char *pwcs, size_t len, int encoding,
301300
elseif (w <=0)/* Non-ascii control char */
302301
{
303302
if (encoding==PG_UTF8)
304-
sprintf(ptr,"\\u%04X",utf2ucs(pwcs));
303+
sprintf((char*)ptr,"\\u%04X",utf2ucs(pwcs));
305304
else
306305
/* This case cannot happen in the current
307306
* code because only UTF-8 signals multibyte
308307
* control characters. But we may need to
309308
* support it at some stage */
310-
sprintf(ptr,"\\u????");
309+
sprintf((char*)ptr,"\\u????");
311310

312311
ptr+=6;
313312
linewidth+=6;

‎src/bin/psql/print.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.81 2006/02/1015:48:05 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.82 2006/02/1022:29:06 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -357,8 +357,8 @@ print_aligned_text(const char *title, const char *const * headers,
357357
{
358358
unsignedintcol_count=0;
359359
unsignedintcell_count=0;
360-
unsignedinti,
361-
tmp;
360+
unsignedinti;
361+
inttmp;
362362
unsignedint*widths,
363363
total_w;
364364
unsignedint*heights;
@@ -583,17 +583,22 @@ print_aligned_text(const char *title, const char *const * headers,
583583
{
584584
if (opt_numeric_locale)
585585
{
586-
/* Assumption: This code used only on strings
586+
/*
587+
* Assumption: This code used only on strings
587588
* without multibyte characters, otherwise
588589
* this_line->width < strlen(this_ptr) and we
589-
* get an overflow */
590-
591-
char*my_cell=format_numeric_locale(this_line->ptr);
592-
fprintf(fout,"%*s%s",widths[i %col_count]-strlen(my_cell),"",my_cell);
590+
* get an overflow
591+
*/
592+
char*my_cell=format_numeric_locale((char*)this_line->ptr);
593+
fprintf(fout,"%*s%s",
594+
(int) (widths[i %col_count]-strlen(my_cell)),"",
595+
my_cell);
593596
free(my_cell);
594597
}
595598
else
596-
fprintf(fout,"%*s%s",widths[j]-this_line->width,"",this_line->ptr);
599+
fprintf(fout,"%*s%s",
600+
widths[j]-this_line->width,"",
601+
this_line->ptr);
597602
}
598603
else
599604
fprintf(fout,"%-s%*s",this_line->ptr,
@@ -665,13 +670,13 @@ print_aligned_vertical(const char *title, const char *const * headers,
665670
unsignedintrecord=1;
666671
constchar*const*ptr;
667672
unsignedinti,
668-
tmp=0,
669673
hwidth=0,
670674
dwidth=0,
671675
hheight=1,
672676
dheight=1,
673677
hformatsize=0,
674678
dformatsize=0;
679+
inttmp=0;
675680
char*divider;
676681
unsignedintcell_count=0;
677682
structlineptr*hlineptr,*dlineptr;
@@ -823,11 +828,12 @@ print_aligned_vertical(const char *title, const char *const * headers,
823828
{
824829
if (opt_align[i %col_count]=='r'&&opt_numeric_locale)
825830
{
826-
char*my_cell=format_numeric_locale(dlineptr[line_count].ptr);
831+
char*my_cell=format_numeric_locale((char*)dlineptr[line_count].ptr);
827832
if (opt_border<2)
828833
fprintf(fout,"%s\n",my_cell);
829834
else
830-
fprintf(fout,"%-s%*s |\n",my_cell,dwidth-strlen(my_cell),"");
835+
fprintf(fout,"%-s%*s |\n",my_cell,
836+
(int) (dwidth-strlen(my_cell)),"");
831837
free(my_cell);
832838
}
833839
else
@@ -1753,7 +1759,8 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
17531759
headers=pg_local_calloc(nfields+1,sizeof(*headers));
17541760

17551761
for (i=0;i<nfields;i++)
1756-
headers[i]=mbvalidate(PQfname(result,i),opt->topt.encoding);
1762+
headers[i]= (char*)mbvalidate((unsignedchar*)PQfname(result,i),
1763+
opt->topt.encoding);
17571764

17581765
/* set cells */
17591766
ncells=PQntuples(result)*nfields;
@@ -1764,7 +1771,9 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
17641771
if (PQgetisnull(result,i /nfields,i %nfields))
17651772
cells[i]=opt->nullPrint ?opt->nullPrint :"";
17661773
else
1767-
cells[i]=mbvalidate(PQgetvalue(result,i /nfields,i %nfields),opt->topt.encoding);
1774+
cells[i]= (char*)
1775+
mbvalidate((unsignedchar*)PQgetvalue(result,i /nfields,i %nfields),
1776+
opt->topt.encoding);
17681777
}
17691778

17701779
/* set footers */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp