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 856cdf8..8996bd0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 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.
        * lib/striconveh.c (mem_iconveh): New function.
        * tests/test-striconveh.c (main): Add tests for mem_iconveh.
index b2490a7..7c4f549 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 c27ef98..235e606 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