|
17 | 17 | * Portions Copyright (c) 1996-2000, PostgreSQL, Inc |
18 | 18 | * Portions Copyright (c) 1994, Regents of the University of California |
19 | 19 | * |
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 $ |
21 | 21 | * |
22 | 22 | *------------------------------------------------------------------------- |
23 | 23 | */ |
@@ -99,6 +99,9 @@ termPQExpBuffer(PQExpBuffer str) |
99 | 99 | free(str->data); |
100 | 100 | str->data=NULL; |
101 | 101 | } |
| 102 | +/* just for luck, make the buffer validly empty. */ |
| 103 | +str->maxlen=0; |
| 104 | +str->len=0; |
102 | 105 | } |
103 | 106 |
|
104 | 107 | /*------------------------ |
@@ -139,7 +142,7 @@ enlargePQExpBuffer(PQExpBuffer str, size_t needed) |
139 | 142 | * overflows. Actually, we might need to more than double it if |
140 | 143 | * 'needed' is big... |
141 | 144 | */ |
142 | | -newlen=str->maxlen ? (2*str->maxlen) :64; |
| 145 | +newlen=(str->maxlen>0) ? (2*str->maxlen) :64; |
143 | 146 | while (needed>newlen) |
144 | 147 | newlen=2*newlen; |
145 | 148 |
|
@@ -177,9 +180,9 @@ printfPQExpBuffer(PQExpBuffer str, const char *fmt,...) |
177 | 180 | * just fall through to enlarge the buffer first. |
178 | 181 | *---------- |
179 | 182 | */ |
180 | | -avail=str->maxlen-str->len-1; |
181 | | -if (avail>16) |
| 183 | +if (str->maxlen>str->len+16) |
182 | 184 | { |
| 185 | +avail=str->maxlen-str->len-1; |
183 | 186 | va_start(args,fmt); |
184 | 187 | nprinted=vsnprintf(str->data+str->len,avail, |
185 | 188 | fmt,args); |
@@ -226,9 +229,9 @@ appendPQExpBuffer(PQExpBuffer str, const char *fmt,...) |
226 | 229 | * just fall through to enlarge the buffer first. |
227 | 230 | *---------- |
228 | 231 | */ |
229 | | -avail=str->maxlen-str->len-1; |
230 | | -if (avail>16) |
| 232 | +if (str->maxlen>str->len+16) |
231 | 233 | { |
| 234 | +avail=str->maxlen-str->len-1; |
232 | 235 | va_start(args,fmt); |
233 | 236 | nprinted=vsnprintf(str->data+str->len,avail, |
234 | 237 | fmt,args); |
|