aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>1998-11-29 01:53:54 +0000
committerTom Lane <tgl@sss.pgh.pa.us>1998-11-29 01:53:54 +0000
commit67531c42bd247540343716ea794edd5a5e1ccaff (patch)
treecd4c355e1e1a27a00350fb673b9614f0b32a00e0 /src
parent79fcde48b229534fd4a5e07834e5e0e84dd38bee (diff)
downloadpostgresql-67531c42bd247540343716ea794edd5a5e1ccaff.tar.gz
postgresql-67531c42bd247540343716ea794edd5a5e1ccaff.zip
Portability fix for old SunOS releases: realloc(NULL, ...)
doesn't work there.
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/libpq/fe-exec.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index e6742a4769f..4e9b1530d37 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.70 1998/11/18 00:47:28 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.71 1998/11/29 01:53:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -343,17 +343,23 @@ addTuple(PGresult *res, PGresAttValue *tup)
*
* We can use realloc because shallow copying of the structure is
* okay. Note that the first time through, res->tuples is NULL.
- * realloc is supposed to do the right thing in that case. Also,
- * on failure realloc is supposed to return NULL without damaging
+ * While ANSI says that realloc() should act like malloc() in that
+ * case, some old C libraries (like SunOS 4.1.x) coredump instead.
+ * On failure realloc is supposed to return NULL without damaging
* the existing allocation.
* Note that the positions beyond res->ntups are garbage, not
* necessarily NULL.
*/
int newSize = (res->tupArrSize > 0) ? res->tupArrSize * 2 : 128;
- PGresAttValue ** newTuples = (PGresAttValue **)
- realloc(res->tuples, newSize * sizeof(PGresAttValue *));
+ PGresAttValue ** newTuples;
+ if (res->tuples == NULL)
+ newTuples = (PGresAttValue **)
+ malloc(newSize * sizeof(PGresAttValue *));
+ else
+ newTuples = (PGresAttValue **)
+ realloc(res->tuples, newSize * sizeof(PGresAttValue *));
if (! newTuples)
- return FALSE; /* realloc failed */
+ return FALSE; /* malloc or realloc failed */
res->tupArrSize = newSize;
res->tuples = newTuples;
}