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 70a9faf2ee3ff0d3212461da6e7a2036d5376a1f..3facc4a77b36af6716cd74108ec79fb8dcc15e97 100644 (file)
 
 
 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;
 }