Skip to content

Commit f4d0475

Browse files
committed
Merge branch 'Explorer09-xsnprintf-len'
2 parents 0e2eed0 + 7c6c9d3 commit f4d0475

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

XUtils.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ in the source distribution for its full text.
1212
#include <assert.h>
1313
#include <errno.h>
1414
#include <fcntl.h>
15+
#include <limits.h>
1516
#include <math.h>
1617
#include <stdarg.h>
1718
#include <stdint.h>
@@ -251,6 +252,9 @@ int xAsprintf(char** strp, const char* fmt, ...) {
251252
int xSnprintf(char* buf, size_t len, const char* fmt, ...) {
252253
assert(len > 0);
253254

255+
// POSIX says snprintf() can fail if (len > INT_MAX).
256+
len = MINIMUM(INT_MAX, len);
257+
254258
va_list vl;
255259
va_start(vl, fmt);
256260
int n = vsnprintf(buf, len, fmt, vl);

0 commit comments

Comments
 (0)