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

Commite143598

Browse files
committed
Fix memory stomp that's turning the whole buildfarm pink: you can't hack up
pg_wcsformat without changing pg_wcssize to match. Add some comments totry to make that clearer, and make a couple other minor editorializations.
1 parentc56b444 commite143598

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

‎src/bin/psql/mbprint.c

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.32 2008/05/08 19:11:36 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.33 2008/05/09 05:25:04 tgl Exp $
77
*
88
* XXX this file does not really belong in psql/. Perhaps move to libpq?
99
* It also seems that the mbvalidate function is redundant with existing
@@ -205,12 +205,15 @@ pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding)
205205
* pg_wcssize takes the given string in the given encoding and returns three
206206
* values:
207207
* result_width: Width in display characters of the longest line in string
208-
* result_height: Number of newlines in display output
209-
* result_format_size: Number of bytes required to store formatted representation of string
208+
* result_height: Number of lines in display output
209+
* result_format_size: Number of bytes required to store formatted
210+
*representation of string
211+
*
212+
* This MUST be kept in sync with pg_wcsformat!
210213
*/
211-
int
212-
pg_wcssize(unsignedchar*pwcs,size_tlen,intencoding,int*result_width,
213-
int*result_height,int*result_format_size)
214+
void
215+
pg_wcssize(unsignedchar*pwcs,size_tlen,intencoding,
216+
int*result_width,int*result_height,int*result_format_size)
214217
{
215218
intw,
216219
chlen=0,
@@ -241,6 +244,14 @@ pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *result_width,
241244
linewidth+=2;
242245
format_size+=2;
243246
}
247+
elseif (*pwcs=='\t')/* Tab */
248+
{
249+
do
250+
{
251+
linewidth++;
252+
format_size++;
253+
}while (linewidth %8!=0);
254+
}
244255
elseif (w<0)/* Other control char */
245256
{
246257
linewidth+=4;
@@ -266,7 +277,7 @@ pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *result_width,
266277
}
267278
if (linewidth>width)
268279
width=linewidth;
269-
format_size+=1;
280+
format_size+=1;/* For NUL char */
270281

271282
/* Set results */
272283
if (result_width)
@@ -275,14 +286,13 @@ pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *result_width,
275286
*result_height=height;
276287
if (result_format_size)
277288
*result_format_size=format_size;
278-
279-
returnwidth;
280289
}
281290

282291
/*
283-
* Filter out unprintable characters, companion to wcs_size.
284-
* Break input into lines based on \n. lineptr[i].ptr == NULL
285-
*indicates the end of the array.
292+
* Format a string into one or more "struct lineptr" lines.
293+
* lines[i].ptr == NULL indicates the end of the array.
294+
*
295+
* This MUST be kept in sync with pg_wcssize!
286296
*/
287297
void
288298
pg_wcsformat(unsignedchar*pwcs,size_tlen,intencoding,
@@ -309,7 +319,7 @@ pg_wcsformat(unsigned char *pwcs, size_t len, int encoding,
309319
linewidth=0;
310320
lines++;
311321
count--;
312-
if (count==0)
322+
if (count<=0)
313323
exit(1);/* Screwup */
314324

315325
/* make next line point to remaining memory */
@@ -346,14 +356,14 @@ pg_wcsformat(unsigned char *pwcs, size_t len, int encoding,
346356
if (encoding==PG_UTF8)
347357
sprintf((char*)ptr,"\\u%04X",utf2ucs(pwcs));
348358
else
349-
359+
{
350360
/*
351361
* This case cannot happen in the current code because only
352362
* UTF-8 signals multibyte control characters. But we may need
353363
* to support it at some stage
354364
*/
355365
sprintf((char*)ptr,"\\u????");
356-
366+
}
357367
ptr+=6;
358368
linewidth+=6;
359369
}
@@ -370,7 +380,7 @@ pg_wcsformat(unsigned char *pwcs, size_t len, int encoding,
370380
lines->width=linewidth;
371381
*ptr++='\0';/* Terminate formatted string */
372382

373-
if (count==0)
383+
if (count<=0)
374384
exit(1);/* Screwup */
375385

376386
(lines+1)->ptr=NULL;/* terminate line array */

‎src/bin/psql/mbprint.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/bin/psql/mbprint.h,v 1.11 2006/10/04 00:30:06 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/bin/psql/mbprint.h,v 1.12 2008/05/09 05:25:04 tgl Exp $ */
22
#ifndefMBPRINT_H
33
#defineMBPRINT_H
44

@@ -13,6 +13,7 @@ extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding);
1313

1414
externintpg_wcswidth(constunsignedchar*pwcs,size_tlen,intencoding);
1515
externvoidpg_wcsformat(unsignedchar*pwcs,size_tlen,intencoding,structlineptr*lines,intcount);
16-
externintpg_wcssize(unsignedchar*pwcs,size_tlen,intencoding,int*width,int*height,int*format_size);
16+
externvoidpg_wcssize(unsignedchar*pwcs,size_tlen,intencoding,
17+
int*width,int*height,int*format_size);
1718

1819
#endif/* MBPRINT_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp