Ensure errno when strdup fails.
authorBruno Haible <bruno@clisp.org>
Sun, 21 Jan 2007 22:18:23 +0000 (22:18 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 21 Jan 2007 22:18:23 +0000 (22:18 +0000)
ChangeLog
lib/striconv.c
lib/striconveh.c

index 856cdf86c5a31dd7418d5775a57d545791dd82aa..8996bd0b0b715043a27a2ed831e396efc48ac262 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-01-21  Bruno Haible  <bruno@clisp.org>
+
+       * lib/striconv.c (str_iconv): Guarantee errno is set when strdup fails.
+       * lib/striconveh.c (str_iconveh): Likewise.
+
 2007-01-21  Bruno Haible  <bruno@clisp.org>
 
        * lib/striconveh.h (mem_iconveh): New declaration.
index b2490a750d13bcebc3c5e63fa07605b67371ef3f..7c4f549cf6ffd0ba5e5b48623b94abddba25ee04 100644 (file)
@@ -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
index c27ef98eb4016a18e5a6ca060f22926c7285cf37..235e606350ee8626356a8d2a3a8914d33d6a8bbd 100644 (file)
@@ -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