diff th_printf.c @ 704:b6b8e7249666

Check that the buffer length is >= 1 before trying to access buf[len - 1]
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 26 Apr 2020 23:34:21 +0300
parents 284d5b789b7c
children 4ca6a3b30fe8
line wrap: on
line diff
--- a/th_printf.c	Sun Apr 26 23:30:17 2020 +0300
+++ b/th_printf.c	Sun Apr 26 23:34:21 2020 +0300
@@ -121,7 +121,7 @@
     (void) prec;
 
     // This is not very nice
-    if (buf[len - 1] != '0')
+    if (len < 1 || buf[len - 1] != '0')
     {
         if (*prec > 0)
             (*prec)--;