diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2016-03-03 21:01:00 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2016-03-03 21:01:00 +0200 |
commit | 596cc77d097139e34be50240a60e849d423a3f4a (patch) | |
tree | bec1fd0aba6da95ea24921b132af1d50cc48fb23 /profile.c | |
parent | 7ea8855c0c000f407499073c930ca4bd92994af8 (diff) | |
parent | d78adb29468012f54dd029e021d83eb668f19a7d (diff) | |
download | egawk-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.c | 42 |
1 files changed, 24 insertions, 18 deletions
@@ -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]; |