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

Commit67531c4

Browse files
committed
Portability fix for old SunOS releases: realloc(NULL, ...)
doesn't work there.
1 parent79fcde4 commit67531c4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

‎src/interfaces/libpq/fe-exec.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* 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 $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -343,17 +343,23 @@ addTuple(PGresult *res, PGresAttValue *tup)
343343
*
344344
* We can use realloc because shallow copying of the structure is
345345
* 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
348349
* the existing allocation.
349350
* Note that the positions beyond res->ntups are garbage, not
350351
* necessarily NULL.
351352
*/
352353
intnewSize= (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*));
355361
if (!newTuples)
356-
return FALSE;/* realloc failed */
362+
return FALSE;/*malloc orrealloc failed */
357363
res->tupArrSize=newSize;
358364
res->tuples=newTuples;
359365
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp