Bug 826171 - Fix strndup in memory/build/mozmemory_wrap.c. r=jlebar
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 03 Jan 2013 16:05:20 +0100
changeset 117442 facbbe4359061e289222699c039c9c2ef48f2832
parent 117441 b28771946018e90626908eb28b1d934d69a34765
child 117443 25f4720f84a71562b6b01e840e344e2d98f04ac8
push id24101
push usereakhgari@mozilla.com
push dateFri, 04 Jan 2013 17:24:40 +0000
treeherdermozilla-central@259982750c29 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlebar
bugs826171
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 826171 - Fix strndup in memory/build/mozmemory_wrap.c. r=jlebar
memory/build/mozmemory_wrap.c
--- a/memory/build/mozmemory_wrap.c
+++ b/memory/build/mozmemory_wrap.c
@@ -68,18 +68,20 @@ mozmem_malloc_impl(_ZdaPvRKSt9nothrow_t)
 #undef strndup
 #undef strdup
 
 #ifndef XP_DARWIN
 MOZ_MEMORY_API char *
 strndup_impl(const char *src, size_t len)
 {
   char* dst = (char*) malloc_impl(len + 1);
-  if (dst)
-    strncpy(dst, src, len + 1);
+  if (dst) {
+    strncpy(dst, src, len);
+    dst[len] = '\0';
+  }
   return dst;
 }
 
 MOZ_MEMORY_API char *
 strdup_impl(const char *src)
 {
   size_t len = strlen(src);
   return strndup_impl(src, len);