]> granicus.if.org Git - postgresql/commitdiff
Fix our version of strdup() to adhere to the standard semantics for
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 27 Sep 2005 04:53:23 +0000 (04:53 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 27 Sep 2005 04:53:23 +0000 (04:53 +0000)
out-of-memory --- that is, return NULL rather than dumping core.
Noted by Qingqing Zhou.

src/port/strdup.c

index 2854b6601102d244a1e31da3c2d3eba370d99c73..22f842da16da2d1fed92d75e5b3eb57892e01e0f 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/port/strdup.c,v 1.7 2005/07/28 04:03:14 tgl Exp $
+ *       $PostgreSQL: pgsql/src/port/strdup.c,v 1.8 2005/09/27 04:53:23 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 
 
 char *
-strdup(char const * string)
+strdup(const char *string)
 {
        char       *nstr;
 
-       nstr = strcpy((char *) malloc(strlen(string) + 1), string);
+       nstr = (char *) malloc(strlen(string) + 1);
+       if (nstr)
+               strcpy(nstr, string);
        return nstr;
 }