diff options
Diffstat (limited to 'firmware/common/sprintf.c')
-rw-r--r-- | firmware/common/sprintf.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/firmware/common/sprintf.c b/firmware/common/sprintf.c index bbd4db5bb4..6f9d7bc248 100644 --- a/firmware/common/sprintf.c +++ b/firmware/common/sprintf.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <stdarg.h> | 27 | #include <stdarg.h> |
28 | #include <string.h> | 28 | #include <string.h> |
29 | #include <stdbool.h> | 29 | #include <stdbool.h> |
30 | #include <limits.h> | ||
30 | 31 | ||
31 | #include "file.h" /* for write(), used in fprintf() */ | 32 | #include "file.h" /* for write(), used in fprintf() */ |
32 | #include "sprintf.h" /* to allow the simulator magic */ | 33 | #include "sprintf.h" /* to allow the simulator magic */ |
@@ -75,6 +76,8 @@ static int format( | |||
75 | precision = 10*precision + ch - '0'; | 76 | precision = 10*precision + ch - '0'; |
76 | ch = *fmt++; | 77 | ch = *fmt++; |
77 | } | 78 | } |
79 | } else { | ||
80 | precision = INT_MAX; | ||
78 | } | 81 | } |
79 | 82 | ||
80 | str = tmpbuf + sizeof tmpbuf - 1; | 83 | str = tmpbuf + sizeof tmpbuf - 1; |
@@ -86,8 +89,6 @@ static int format( | |||
86 | 89 | ||
87 | case 's': | 90 | case 's': |
88 | str = va_arg (ap, char*); | 91 | str = va_arg (ap, char*); |
89 | if(precision > 0) | ||
90 | str[precision] = '\0'; | ||
91 | break; | 92 | break; |
92 | 93 | ||
93 | case 'd': | 94 | case 'd': |
@@ -160,7 +161,7 @@ static int format( | |||
160 | while (width-- > 0 && ok) | 161 | while (width-- > 0 && ok) |
161 | ok=push(userp, pad); | 162 | ok=push(userp, pad); |
162 | } | 163 | } |
163 | while (*str != '\0' && ok) | 164 | while (*str != '\0' && ok && precision--) |
164 | ok=push(userp, *str++); | 165 | ok=push(userp, *str++); |
165 | } | 166 | } |
166 | else | 167 | else |