pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pre-lexer 01/21] str: Make ss_alloc_substring() allocate null-terminate


From: Ben Pfaff
Subject: [pre-lexer 01/21] str: Make ss_alloc_substring() allocate null-terminated strings.
Date: Thu, 23 Sep 2010 21:20:37 -0700

This has little cost and it is occasionally valuable.
---
 src/libpspp/str.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/libpspp/str.c b/src/libpspp/str.c
index bde4de4..9f0cb6e 100644
--- a/src/libpspp/str.c
+++ b/src/libpspp/str.c
@@ -30,6 +30,7 @@
 #include <relocatable.h>
 #include "minmax.h"
 #include "xalloc.h"
+#include "xmemdup0.h"
 #include "xsize.h"
 
 /* Reverses the order of NBYTES bytes at address P, thus converting
@@ -379,14 +380,13 @@ ss_tail (struct substring ss, size_t cnt)
     return ss;
 }
 
-/* Makes a malloc()'d copy of the contents of OLD
+/* Makes a malloc()'d, null-terminated copy of the contents of OLD
    and stores it in NEW. */
 void
 ss_alloc_substring (struct substring *new, struct substring old)
 {
-  new->string = xmalloc (old.length);
+  new->string = xmemdup0 (old.string, old.length);
   new->length = old.length;
-  memcpy (new->string, old.string, old.length);
 }
 
 /* Allocates room for a CNT-character string in NEW. */
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]