|
7 | 7 | *
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.70 1998/11/18 00:47:28 tgl Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.71 1998/11/29 01:53:54 tgl Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -343,17 +343,23 @@ addTuple(PGresult *res, PGresAttValue *tup)
|
343 | 343 | *
|
344 | 344 | * We can use realloc because shallow copying of the structure is
|
345 | 345 | * okay. Note that the first time through, res->tuples is NULL.
|
346 |
| - * realloc is supposed to do the right thing in that case. Also, |
347 |
| - * on failure realloc is supposed to return NULL without damaging |
| 346 | + * While ANSI says that realloc() should act like malloc() in that |
| 347 | + * case, some old C libraries (like SunOS 4.1.x) coredump instead. |
| 348 | + * On failure realloc is supposed to return NULL without damaging |
348 | 349 | * the existing allocation.
|
349 | 350 | * Note that the positions beyond res->ntups are garbage, not
|
350 | 351 | * necessarily NULL.
|
351 | 352 | */
|
352 | 353 | int newSize = (res->tupArrSize > 0) ? res->tupArrSize * 2 : 128;
|
353 |
| - PGresAttValue ** newTuples = (PGresAttValue **) |
354 |
| - realloc(res->tuples, newSize * sizeof(PGresAttValue *)); |
| 354 | + PGresAttValue ** newTuples; |
| 355 | + if (res->tuples == NULL) |
| 356 | + newTuples = (PGresAttValue **) |
| 357 | + malloc(newSize * sizeof(PGresAttValue *)); |
| 358 | + else |
| 359 | + newTuples = (PGresAttValue **) |
| 360 | + realloc(res->tuples, newSize * sizeof(PGresAttValue *)); |
355 | 361 | if (! newTuples)
|
356 |
| - return FALSE; /* realloc failed */ |
| 362 | + return FALSE; /* malloc or realloc failed */ |
357 | 363 | res->tupArrSize = newSize;
|
358 | 364 | res->tuples = newTuples;
|
359 | 365 | }
|
|
0 commit comments