summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <programble@gmail.com>2016-10-08 17:38:37 -0400
committerJune McEnroe <programble@gmail.com>2016-10-08 17:38:37 -0400
commit956af8b4527a9b6a8b3016aecd67ace34da595ad (patch)
treef12e3506ac45b8527cd58bc1633e385a48977d64
parentAdd quote to jrp and refactor jit (diff)
downloadsrc-956af8b4527a9b6a8b3016aecd67ace34da595ad.tar.gz
src-956af8b4527a9b6a8b3016aecd67ace34da595ad.zip
Fix jrp prompt snprintf
-rwxr-xr-x.bin/jrp.c9
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] = '[';