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 126544 facbbe4359061e289222699c039c9c2ef48f2832
parent 126543 b28771946018e90626908eb28b1d934d69a34765
child 126545 25f4720f84a71562b6b01e840e344e2d98f04ac8
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [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);