From: Florian Forster Date: Sat, 20 Dec 2008 15:55:10 +0000 (+0100) Subject: src/common.c: Change `sstrdup' to not call `strdup' anymore. X-Git-Tag: collectd-4.6.0~121 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f73c5b3069fd10048f1fcdf5266d8da2fcb403e5;p=collectd.git src/common.c: Change `sstrdup' to not call `strdup' anymore. --- diff --git a/src/common.c b/src/common.c index 119d284f..ae89c44f 100644 --- a/src/common.c +++ b/src/common.c @@ -77,15 +77,21 @@ int ssnprintf (char *dest, size_t n, const char *format, ...) char *sstrdup (const char *s) { char *r; + size_t sz; if (s == NULL) return (NULL); - if((r = strdup (s)) == NULL) + /* Do not use `strdup' here, because it's not specified in POSIX. It's + * ``only'' an XSI extension. */ + sz = strlen (s) + 1; + r = (char *) malloc (sizeof (char) * sz); + if (r == NULL) { - ERROR ("Not enough memory."); + ERROR ("sstrdup: Out of memory."); exit (3); } + memcpy (r, s, sizeof (char) * sz); return (r); } /* char *sstrdup */