From 131ca96f8e1b8675e80b37ad6cedca1b21b87e87 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 10 Sep 2010 21:07:00 -0700 Subject: [PATCH] str: Make ss_alloc_substring() allocate null-terminated strings. This has little cost and it is occasionally valuable. --- src/libpspp/str.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libpspp/str.c b/src/libpspp/str.c index bde4de4be5..9f0cb6e314 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -30,6 +30,7 @@ #include #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. */ -- 2.30.2