|
7 | 7 | *
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.69 1998/10/01 01:40:21 tgl Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.69.2.1 1998/11/29 01:54:34 tgl Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -214,17 +214,23 @@ addTuple(PGresult *res, PGresAttValue *tup)
|
214 | 214 | *
|
215 | 215 | * We can use realloc because shallow copying of the structure is
|
216 | 216 | * okay. Note that the first time through, res->tuples is NULL.
|
217 |
| - * realloc is supposed to do the right thing in that case. Also, |
218 |
| - * on failure realloc is supposed to return NULL without damaging |
| 217 | + * While ANSI says that realloc() should act like malloc() in that |
| 218 | + * case, some old C libraries (like SunOS 4.1.x) coredump instead. |
| 219 | + * On failure realloc is supposed to return NULL without damaging |
219 | 220 | * the existing allocation.
|
220 | 221 | * Note that the positions beyond res->ntups are garbage, not
|
221 | 222 | * necessarily NULL.
|
222 | 223 | */
|
223 | 224 | int newSize = res->tupArrSize + TUPARR_GROW_BY;
|
224 |
| - PGresAttValue ** newTuples = (PGresAttValue **) |
225 |
| - realloc(res->tuples, newSize * sizeof(PGresAttValue *)); |
| 225 | + PGresAttValue ** newTuples; |
| 226 | + if (res->tuples == NULL) |
| 227 | + newTuples = (PGresAttValue **) |
| 228 | + malloc(newSize * sizeof(PGresAttValue *)); |
| 229 | + else |
| 230 | + newTuples = (PGresAttValue **) |
| 231 | + realloc(res->tuples, newSize * sizeof(PGresAttValue *)); |
226 | 232 | if (! newTuples)
|
227 |
| - return FALSE; /* realloc failed */ |
| 233 | + return FALSE; /* malloc or realloc failed */ |
228 | 234 | res->tupArrSize = newSize;
|
229 | 235 | res->tuples = newTuples;
|
230 | 236 | }
|
|
0 commit comments