From: Bruno Haible Date: Sun, 21 Jan 2007 22:18:23 +0000 (+0000) Subject: Ensure errno when strdup fails. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec32a9f497d23fc1d7c7e0847ec008ca5a8bb299;p=pspp Ensure errno when strdup fails. --- diff --git a/ChangeLog b/ChangeLog index 856cdf86c5..8996bd0b0b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-01-21 Bruno Haible + + * lib/striconv.c (str_iconv): Guarantee errno is set when strdup fails. + * lib/striconveh.c (str_iconveh): Likewise. + 2007-01-21 Bruno Haible * lib/striconveh.h (mem_iconveh): New declaration. diff --git a/lib/striconv.c b/lib/striconv.c index b2490a750d..7c4f549cf6 100644 --- a/lib/striconv.c +++ b/lib/striconv.c @@ -398,7 +398,13 @@ char * str_iconv (const char *src, const char *from_codeset, const char *to_codeset) { if (c_strcasecmp (from_codeset, to_codeset) == 0) - return strdup (src); + { + char *result = strdup (src); + + if (result == NULL) + errno = ENOMEM; + return result; + } else { #if HAVE_ICONV diff --git a/lib/striconveh.c b/lib/striconveh.c index c27ef98eb4..235e606350 100644 --- a/lib/striconveh.c +++ b/lib/striconveh.c @@ -920,7 +920,13 @@ str_iconveh (const char *src, enum iconv_ilseq_handler handler) { if (c_strcasecmp (from_codeset, to_codeset) == 0) - return strdup (src); + { + char *result = strdup (src); + + if (result == NULL) + errno = ENOMEM; + return result; + } else { #if HAVE_ICONV