X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fstr.c;h=9f0cb6e31463ab5caf319114e43fed26f640ae2b;hb=refs%2Ftags%2Fsav-api;hp=bde4de4be5bb4ee13edf877e217537336debfc0a;hpb=c75794cffb05769b71a346af8513a3e8dde55f94;p=pspp 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. */