aboutsummaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/profile.c b/profile.c
index 64aeaa9c..43875600 100644
--- a/profile.c
+++ b/profile.c
@@ -1539,33 +1539,39 @@ pp_list(int nargs, const char *paren, const char *delim)
}
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 {
+ 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];