aboutsummaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-02-29 21:34:57 +0200
committerArnold D. Robbins <arnold@skeeve.com>2016-02-29 21:34:57 +0200
commit21b584ce481970c9022c08148a6adbc0e489c432 (patch)
tree1b67978ae32a437958c1d69b4dc856d58172aca0 /profile.c
parentbfca1619d658bc30835f4fb29c53ddfe206f4b17 (diff)
downloadegawk-21b584ce481970c9022c08148a6adbc0e489c432.tar.gz
egawk-21b584ce481970c9022c08148a6adbc0e489c432.tar.bz2
egawk-21b584ce481970c9022c08148a6adbc0e489c432.zip
Fix profiling bug - printf with no arguments.
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/profile.c b/profile.c
index d002e237..178deb7e 100644
--- a/profile.c
+++ b/profile.c
@@ -1423,34 +1423,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];