Stop using strncpy unnecessarily. b=391766 r+a=brendan
authordbaron@dbaron.org
Fri, 10 Aug 2007 17:52:35 -0700
changeset 4512 4e14c8e29ed5c3f15cb1a913a06a02992873ceb2
parent 4511 94b7fd2bb56aaa0189f7d6f4703514273e511456
child 4513 2b9cf1b220473cbf86dd8dcc3b48754758803550
push idunknown
push userunknown
push dateunknown
bugs391766
milestone1.9a8pre
Stop using strncpy unnecessarily. b=391766 r+a=brendan
tools/trace-malloc/lib/nsTraceMalloc.c
--- a/tools/trace-malloc/lib/nsTraceMalloc.c
+++ b/tools/trace-malloc/lib/nsTraceMalloc.c
@@ -333,30 +333,27 @@ static void log_byte(logfile *fp, char b
         flush_logfile(fp);
     fp->buf[fp->pos++] = byte;
 }
 
 static void log_string(logfile *fp, const char *str)
 {
     int len, rem, cnt;
 
-    len = strlen(str);
+    len = strlen(str) + 1; /* include null terminator */
     while ((rem = fp->pos + len - fp->bufsize) > 0) {
         cnt = len - rem;
-        strncpy(&fp->buf[fp->pos], str, cnt);
+        memcpy(&fp->buf[fp->pos], str, cnt);
         str += cnt;
         fp->pos += cnt;
         flush_logfile(fp);
         len = rem;
     }
-    strncpy(&fp->buf[fp->pos], str, len);
+    memcpy(&fp->buf[fp->pos], str, len);
     fp->pos += len;
-
-    /* Terminate the string. */
-    log_byte(fp, '\0');
 }
 
 static void log_filename(logfile* fp, const char* filename)
 {
     if (strlen(filename) < 512) {
         char *bp, *cp, buf[512];
 
         bp = strstr(strcpy(buf, filename), "mozilla");