aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Saxby <joshua.a.saxby@gmail.com>2023-04-21 22:33:32 +0100
committerGitHub <noreply@github.com>2023-04-21 22:33:32 +0100
commit1d1b64871eacf288229f973c2bbb003fb81d78fc (patch)
tree80a01ca5299590afcc05916837c8f17457548350
parenteaec942f56ceec9c14de5c4185a02602abadd50a (diff)
downloadpsn00bsdk-1d1b64871eacf288229f973c2bbb003fb81d78fc.tar.gz
Add C11 error checking to vsnprintf()
C11 specifies that vsnprintf() is to check for the following conditions: - output buffer or format string are null pointers - buffer size is zero C11 also specifies "constraint handler functions" that may be set, but that's far more involved, and having at least some error-handling for bad arguments like these is probably quite useful. Source: https://en.cppreference.com/w/c/io/vfprintf#:~:text=5%2D8),constraint%20handler%20function%3A
-rw-r--r--libpsn00b/libc/vsprintf.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/libpsn00b/libc/vsprintf.c b/libpsn00b/libc/vsprintf.c
index 9ca4cc5..585d23d 100644
--- a/libpsn00b/libc/vsprintf.c
+++ b/libpsn00b/libc/vsprintf.c
@@ -391,6 +391,9 @@ int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap)
int zero_flag_imp = 0;
int pad_quantity = 0;
int last;
+
+ // C11: required to check these cases and return error if detected
+ if (string == NULL || fmt == NULL || size == 0) { return -1; }
l = strlen(fmt);