X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fstr.c;h=9f0cb6e31463ab5caf319114e43fed26f640ae2b;hb=9da03b3664f8fc0eacc35f77f83c85288a4f406d;hp=71f54474d57f995f8c5b73572e1d8f761b7e934e;hpb=adb78c1da5de2792a8f07b241e72b8bd341fd90b;p=pspp-builds.git diff --git a/src/libpspp/str.c b/src/libpspp/str.c index 71f54474..9f0cb6e3 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. */ @@ -1465,7 +1465,9 @@ ds_relocate (struct string *st) { ds_clear (st); ds_put_cstr (st, rel); - free ((char *) rel); + /* The documentation for relocate says that casting away const + and then freeing is appropriate ... */ + free (CONST_CAST (char *, rel)); } }