From c55956b6a10d0a4d0b151c1be976dc9c344c1103 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 14 Dec 2014 20:38:14 +0200 Subject: More fixes to stop allocating an extra byte. --- profile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index ad879a3c..45eb562c 100644 --- a/profile.c +++ b/profile.c @@ -1337,7 +1337,7 @@ pp_string(const char *in_str, size_t len, int delim) osiz *= 2; \ } ofre -= (l) - osiz = len + 3 + 2; /* initial size; 3 for delim + terminating null */ + osiz = len + 3 + 1; /* initial size; 3 for delim + terminating null */ emalloc(obuf, char *, osiz, "pp_string"); obufout = obuf; ofre = osiz - 1; @@ -1505,7 +1505,7 @@ pp_concat(int nargs) len = -delimlen; for (i = nargs; i >= 1; i--) { r = pp_args[i] = pp_pop(); - len += r->pp_len + delimlen + 2; + len += r->pp_len + delimlen + 1; } emalloc(str, char *, len + 1, "pp_concat"); @@ -1571,7 +1571,7 @@ pp_group3(const char *s1, const char *s2, const char *s3) len1 = strlen(s1); len2 = strlen(s2); len3 = strlen(s3); - l = len1 + len2 + len3 + 2; + l = len1 + len2 + len3 + 1; emalloc(str, char *, l, "pp_group3"); s = str; if (len1 > 0) { -- cgit v1.2.3 From 6e786e9ea47966a9cac7cfef4a4079ac379580b0 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 14 Dec 2014 21:29:24 +0200 Subject: Fix to previous change. Now passes valgrind. --- profile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index 45eb562c..886f2b0c 100644 --- a/profile.c +++ b/profile.c @@ -1505,7 +1505,7 @@ pp_concat(int nargs) len = -delimlen; for (i = nargs; i >= 1; i--) { r = pp_args[i] = pp_pop(); - len += r->pp_len + delimlen + 1; + len += r->pp_len + delimlen + 2; } emalloc(str, char *, len + 1, "pp_concat"); -- cgit v1.2.3 From 24ddf2742b0034089bce38e5f4ebd99b93c6e161 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 9 Apr 2015 18:04:18 +0300 Subject: Further fixes from Andrew Schorr. --- profile.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index d6d49098..32dfca09 100644 --- a/profile.c +++ b/profile.c @@ -1371,10 +1371,9 @@ pp_string(const char *in_str, size_t len, int delim) *obufout++ = '\\'; *obufout++ = delim; } else if (*str == '\0') { - chksize(4); - *obufout++ = '\\'; *obufout++ = '0'; + chksize(2); /* need 2 more chars for this case */ *obufout++ = '0'; *obufout++ = '0'; } else if ((cp = strchr(escapes, *str)) != NULL) { @@ -1384,7 +1383,7 @@ pp_string(const char *in_str, size_t len, int delim) /* NB: Deliberate use of lower-case versions. */ } else if (isascii(*str) && isprint(*str)) { *obufout++ = *str; - ofre += 1; + ofre += 1; /* used 1 less than expected */ } else { size_t len; -- cgit v1.2.3