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

Commit6bb6209

Browse files
committed
Make pqexpbuffer a little more robust, per bug report from Heinz Ekker.
1 parente8990eb commit6bb6209

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

‎src/interfaces/libpq/pqexpbuffer.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
1818
* Portions Copyright (c) 1994, Regents of the University of California
1919
*
20-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/pqexpbuffer.c,v 1.6 2000/04/12 17:17:15 momjian Exp $
20+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/pqexpbuffer.c,v 1.7 2001/01/19 19:39:23 tgl Exp $
2121
*
2222
*-------------------------------------------------------------------------
2323
*/
@@ -99,6 +99,9 @@ termPQExpBuffer(PQExpBuffer str)
9999
free(str->data);
100100
str->data=NULL;
101101
}
102+
/* just for luck, make the buffer validly empty. */
103+
str->maxlen=0;
104+
str->len=0;
102105
}
103106

104107
/*------------------------
@@ -139,7 +142,7 @@ enlargePQExpBuffer(PQExpBuffer str, size_t needed)
139142
* overflows. Actually, we might need to more than double it if
140143
* 'needed' is big...
141144
*/
142-
newlen=str->maxlen ? (2*str->maxlen) :64;
145+
newlen=(str->maxlen>0) ? (2*str->maxlen) :64;
143146
while (needed>newlen)
144147
newlen=2*newlen;
145148

@@ -177,9 +180,9 @@ printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
177180
* just fall through to enlarge the buffer first.
178181
*----------
179182
*/
180-
avail=str->maxlen-str->len-1;
181-
if (avail>16)
183+
if (str->maxlen>str->len+16)
182184
{
185+
avail=str->maxlen-str->len-1;
183186
va_start(args,fmt);
184187
nprinted=vsnprintf(str->data+str->len,avail,
185188
fmt,args);
@@ -226,9 +229,9 @@ appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
226229
* just fall through to enlarge the buffer first.
227230
*----------
228231
*/
229-
avail=str->maxlen-str->len-1;
230-
if (avail>16)
232+
if (str->maxlen>str->len+16)
231233
{
234+
avail=str->maxlen-str->len-1;
232235
va_start(args,fmt);
233236
nprinted=vsnprintf(str->data+str->len,avail,
234237
fmt,args);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp