X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=blobdiff_plain;f=src%2Flibpspp%2Fstr.c;h=08a85ad790f20fe625de485b6c22058226910e2e;hp=ba4a26f1426ac51552dd31885d5cdfff5fea321d;hb=03bfb72314e434ddaa2ff2b770d1d9df2ea1927a;hpb=763b593a5b5773859e3cf739b843cf0bae0359e5 diff --git a/src/libpspp/str.c b/src/libpspp/str.c index ba4a26f1..08a85ad7 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -347,15 +347,16 @@ ss_realloc (struct substring *ss, size_t size) ss->string = xrealloc (ss->string, size); } -/* Makes a pool_alloc_unaligned()'d copy of the contents of OLD - in POOL, and stores it in NEW. */ +/* Makes a pool_alloc_unaligned()'d, null-terminated copy of the contents of + OLD in POOL, and stores it in NEW. */ void ss_alloc_substring_pool (struct substring *new, struct substring old, struct pool *pool) { - new->string = pool_alloc_unaligned (pool, old.length); + new->string = pool_alloc_unaligned (pool, old.length + 1); new->length = old.length; memcpy (new->string, old.string, old.length); + new->string[old.length] = '\0'; } /* Allocates room for a CNT-byte string in NEW in POOL. */