summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-02-28 20:30:28 -0500
committerJakob Kaivo <jkk@ung.org>2019-02-28 20:30:28 -0500
commit4f17393f3b2514945bf3fab0a7179ce6baf67a45 (patch)
tree634f71883bda0303431d8254ef475720d0ffeba6 /src
parent11eb874682b980e611d45edaa2229aa646b97485 (diff)
set max length to a very big number, undefined behavior happens if the user provides too small a buffer
Diffstat (limited to 'src')
-rw-r--r--src/stdio/sprintf.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/stdio/sprintf.c b/src/stdio/sprintf.c
index 2872331a..bf5f5b6c 100644
--- a/src/stdio/sprintf.c
+++ b/src/stdio/sprintf.c
@@ -2,6 +2,13 @@
#include "stdarg.h"
#include "nonstd/io.h"
+#if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
+#include "stdint.h"
+#else
+#include "limits.h"
+#define SIZE_MAX INT_MAX
+#endif
+
/** write formatted output to a string **/
int sprintf(char * restrict s, const char * restrict format, ...)
{
@@ -10,7 +17,7 @@ int sprintf(char * restrict s, const char * restrict format, ...)
struct io_options opt = {0};
opt.fnname = "sprintf";
opt.string = s;
- opt.maxlen = (size_t)-1;
+ opt.maxlen = SIZE_MAX;
va_start(ap, format);
ret = __printf(&opt, format, ap);
va_end(ap);