]> Savannah Git Hosting - gnulib.git/commitdiff
unistr/*, uniconv/*: Fix undefined behaviour.
authorBruno Haible <bruno@clisp.org>
Fri, 8 Mar 2019 23:01:47 +0000 (00:01 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 8 Mar 2019 23:04:48 +0000 (00:04 +0100)
Reported by Jeffrey Walton <noloader@gmail.com>.

* lib/unistr/u-cpy.h (FUNC): Don't invoke memcpy with a zero size.
* lib/unistr/u-cpy-alloc.h (FUNC): Likewise.
* lib/uniconv/u8-conv-from-enc.c (u8_conv_from_encoding): Likewise.
* lib/uniconv/u8-conv-to-enc.c (u8_conv_to_encoding): Likewise.

ChangeLog
lib/uniconv/u8-conv-from-enc.c
lib/uniconv/u8-conv-to-enc.c
lib/unistr/u-cpy-alloc.h
lib/unistr/u-cpy.h

index 074b1caca4758545b94b2f5e6b161b2130319981..687357e6147fd79977a0e596a34ee2168cd3a3d5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2019-03-08  Bruno Haible  <bruno@clisp.org>
+
+       unistr/*, uniconv/*: Fix undefined behaviour.
+       Reported by Jeffrey Walton <noloader@gmail.com>.
+       * lib/unistr/u-cpy.h (FUNC): Don't invoke memcpy with a zero size.
+       * lib/unistr/u-cpy-alloc.h (FUNC): Likewise.
+       * lib/uniconv/u8-conv-from-enc.c (u8_conv_from_encoding): Likewise.
+       * lib/uniconv/u8-conv-to-enc.c (u8_conv_to_encoding): Likewise.
+
 2019-03-08  Bruno Haible  <bruno@clisp.org>
 
        unistr/u8-cmp: Fix undefined behaviour.
index 623dc1f9a2ee97d99c0331143baa03435fb58a6f..f8e9bd920f64bac0c60f5a18cab70ee11a458d4a 100644 (file)
@@ -77,7 +77,8 @@ u8_conv_from_encoding (const char *fromcode,
             }
         }
 
-      memcpy ((char *) result, src, srclen);
+      if (srclen > 0)
+        memcpy ((char *) result, src, srclen);
       *lengthp = srclen;
       return result;
     }
index ff0bc644b8beae7387fa922044838956b1e1b8ff..56e312198f45051030c2d84b6814832efad160ad 100644 (file)
@@ -60,7 +60,8 @@ u8_conv_to_encoding (const char *tocode,
             }
         }
 
-      memcpy (result, (const char *) src, srclen);
+      if (srclen > 0)
+        memcpy (result, (const char *) src, srclen);
       *lengthp = srclen;
       return result;
     }
index 8afa66b37dc3c2bba8b58acc38f751cc3c21c17f..55fef325bf5161ee4ad93e6c0a13efeda9fe79d0 100644 (file)
@@ -33,7 +33,8 @@ FUNC (const UNIT *s, size_t n)
       for (; n > 0; n--)
         *destptr++ = *s++;
 #else
-      memcpy ((char *) dest, (const char *) s, n * sizeof (UNIT));
+      if (n > 0)
+        memcpy ((char *) dest, (const char *) s, n * sizeof (UNIT));
 #endif
     }
   return dest;
index 1dc212972051b41b8c949c20f043a6f402a8b045..c023a2733904f5ab68006713171a9fb5f66a90f9 100644 (file)
@@ -26,7 +26,8 @@ FUNC (UNIT *dest, const UNIT *src, size_t n)
   for (; n > 0; n--)
     *destptr++ = *src++;
 #else
-  memcpy ((char *) dest, (const char *) src, n * sizeof (UNIT));
+  if (n > 0)
+    memcpy ((char *) dest, (const char *) src, n * sizeof (UNIT));
 #endif
   return dest;
 }