diff options
author | June McEnroe <june@causal.agency> | 2016-10-08 17:38:37 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2016-10-08 17:38:37 -0400 |
commit | cd41a42c4b2e94544cb9ada528f59d696a0131b0 (patch) | |
tree | 6f8737bd611f70cb8a8cf151aeee0c76e96218fc | |
parent | Add quote to jrp and refactor jit (diff) | |
download | src-cd41a42c4b2e94544cb9ada528f59d696a0131b0.tar.gz src-cd41a42c4b2e94544cb9ada528f59d696a0131b0.zip |
Fix jrp prompt snprintf
-rwxr-xr-x | .bin/jrp.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/.bin/jrp.c b/.bin/jrp.c index a7f71180..0c6b18f1 100755 --- a/.bin/jrp.c +++ b/.bin/jrp.c @@ -183,11 +183,12 @@ static char *prompt(EditLine *el __attribute((unused))) { static char buf[4096]; char *bp = buf; for (value *sp = stack.limit - 1; sp >= stack.ptr; --sp) { + size_t len = sizeof(buf) - (buf - bp) - 2; switch (radix) { - case 2: bp += snprintf(bp, buf - bp - 2, " %s", fmt_bin(*sp)); break; - case 8: bp += snprintf(bp, buf - bp - 2, " %llo", *sp); break; - case 10: bp += snprintf(bp, buf - bp - 2, " %lld", *sp); break; - case 16: bp += snprintf(bp, buf - bp - 2, " %llx", *sp); break; + case 2: bp += snprintf(bp, len, " %s", fmt_bin(*sp)); break; + case 8: bp += snprintf(bp, len, " %llo", *sp); break; + case 10: bp += snprintf(bp, len, " %lld", *sp); break; + case 16: bp += snprintf(bp, len, " %llx", *sp); break; } } buf[0] = '['; |