diff options
author | June McEnroe <programble@gmail.com> | 2016-10-08 17:38:37 -0400 |
---|---|---|
committer | June McEnroe <programble@gmail.com> | 2016-10-08 17:38:37 -0400 |
commit | 956af8b4527a9b6a8b3016aecd67ace34da595ad (patch) | |
tree | f12e3506ac45b8527cd58bc1633e385a48977d64 | |
parent | Add quote to jrp and refactor jit (diff) | |
download | src-956af8b4527a9b6a8b3016aecd67ace34da595ad.tar.gz src-956af8b4527a9b6a8b3016aecd67ace34da595ad.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] = '['; |