aboutsummaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-03-03 21:01:00 +0200
committerArnold D. Robbins <arnold@skeeve.com>2016-03-03 21:01:00 +0200
commit596cc77d097139e34be50240a60e849d423a3f4a (patch)
treebec1fd0aba6da95ea24921b132af1d50cc48fb23 /profile.c
parent7ea8855c0c000f407499073c930ca4bd92994af8 (diff)
parentd78adb29468012f54dd029e021d83eb668f19a7d (diff)
downloadegawk-596cc77d097139e34be50240a60e849d423a3f4a.tar.gz
egawk-596cc77d097139e34be50240a60e849d423a3f4a.tar.bz2
egawk-596cc77d097139e34be50240a60e849d423a3f4a.zip
Merge branch 'master' into feature/cmake
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];