Skip to content

Commit 1142f61

Browse files
authored
(v)asprintf is supposed to set the returned pointer to NULL if printing fails, let's fix that in swift_vasprintf (#39338)
1 parent 84fad66 commit 1142f61

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

include/swift/Runtime/Portability.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ swift_vasprintf(char **strp, const char *fmt, va_list args) {
3838
int len = vsnprintf(nullptr, 0, fmt, args_for_len);
3939
va_end(args_for_len);
4040

41+
// If we fail for any reason, strp needs to be set to NULL.
42+
*strp = nullptr;
43+
4144
if (len < 0)
4245
return -1;
4346
char *buffer = reinterpret_cast<char *>(malloc(len + 1));

0 commit comments

Comments
 (0)