aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--profile.c44
2 files changed, 30 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 25a83a6e..16de7b94 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-02-29 Arnold D. Robbins <arnold@skeeve.com>
+
+ * profile.c (pp_list): Handle the case of nargs equal to zero.
+ Thanks to Hermann Peifer for the report.
+
2016-02-28 Arnold D. Robbins <arnold@skeeve.com>
* profile.c (pprint): Fix copy-paste error in else handling.
diff --git a/profile.c b/profile.c
index 64aeaa9c..9e4a9b02 100644
--- a/profile.c
+++ b/profile.c
@@ -1538,34 +1538,40 @@ pp_list(int nargs, const char *paren, const char *delim)
erealloc(pp_args, NODE **, (nargs + 2) * sizeof(NODE *), "pp_list");
}
- delimlen = strlen(delim);
- len = -delimlen;
- for (i = 1; i <= nargs; i++) {
- r = pp_args[i] = pp_pop();
- len += r->pp_len + delimlen;
- }
- if (paren != NULL) {
- assert(strlen(paren) == 2);
- len += 2;
+ if (nargs == 0)
+ len = 2;
+ else {
+ delimlen = strlen(delim);
+ len = -delimlen;
+ for (i = 1; i <= nargs; i++) {
+ r = pp_args[i] = pp_pop();
+ len += r->pp_len + delimlen;
+ }
+ if (paren != NULL) {
+ assert(strlen(paren) == 2);
+ len += 2;
+ }
}
emalloc(str, char *, len + 1, "pp_list");
s = str;
if (paren != NULL)
*s++ = paren[0];
- r = pp_args[nargs];
- memcpy(s, r->pp_str, r->pp_len);
- s += r->pp_len;
- pp_free(r);
- for (i = nargs - 1; i > 0; i--) {
- if (delimlen > 0) {
- memcpy(s, delim, delimlen);
- s += delimlen;
- }
- r = pp_args[i];
+ if (nargs > 0) {
+ r = pp_args[nargs];
memcpy(s, r->pp_str, r->pp_len);
s += r->pp_len;
pp_free(r);
+ for (i = nargs - 1; i > 0; i--) {
+ if (delimlen > 0) {
+ memcpy(s, delim, delimlen);
+ s += delimlen;
+ }
+ r = pp_args[i];
+ memcpy(s, r->pp_str, r->pp_len);
+ s += r->pp_len;
+ pp_free(r);
+ }
}
if (paren != NULL)
*s++ = paren[1];