Skip to content

Commit 78efcd4

Browse files
committed
Use snprintf instead of _snprintf on Windows
_snprintf does not guarantee null termination if the size argument is too small. Starting with VS2015, the UCRT provides a C99-compliant snprintf. Use it, and also fix a related issue where _dispatch_client_assert_fail was passing a too-small size.
1 parent 84ac6ac commit 78efcd4

File tree

2 files changed

+1
-2
lines changed

2 files changed

+1
-2
lines changed

src/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ _dispatch_ktrace_impl(uint32_t code, uint64_t a, uint64_t b,
928928
dispatch_assert(_length != -1); \
929929
_msg = (char *)malloc((unsigned)_length + 1); \
930930
dispatch_assert(_msg); \
931-
_snprintf(_msg, (unsigned)_length, "%s" fmt, DISPATCH_ASSERTION_FAILED_MESSAGE, ##__VA_ARGS__); \
931+
snprintf(_msg, (unsigned)_length + 1, "%s" fmt, DISPATCH_ASSERTION_FAILED_MESSAGE, ##__VA_ARGS__); \
932932
_dispatch_assert_crash(_msg); \
933933
free(_msg); \
934934
} while (0)

src/shims/generic_win_stubs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ typedef __typeof__(_Generic((__SIZE_TYPE__)0, \
4444
#define O_NONBLOCK 04000
4545

4646
#define bzero(ptr,len) memset((ptr), 0, (len))
47-
#define snprintf _snprintf
4847

4948
#endif
5049

0 commit comments

Comments
 (0)