asprintf: set result ptr to NULL on error

Message ID 20230119034258.15881-1-kilobyte@angband.pl
State New
Headers
Series asprintf: set result ptr to NULL on error |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Adam Borowski Jan. 19, 2023, 3:42 a.m. UTC
  This is what other implementations do, and it's too easy to assume this
is being done.  Thus, let's avoid a footgun.

Signed-off-by: Adam Borowski <kilobyte@angband.pl>
---
 libio/vasprintf.c | 1 +
 1 file changed, 1 insertion(+)
  

Patch

diff --git a/libio/vasprintf.c b/libio/vasprintf.c
index facc224295..d56a839fe1 100644
--- a/libio/vasprintf.c
+++ b/libio/vasprintf.c
@@ -95,6 +95,7 @@  int
 __vasprintf_internal (char **result_ptr, const char *format, va_list args,
 		      unsigned int mode_flags)
 {
+  *result_ptr = NULL;
   struct __printf_buffer_asprintf buf;
   __printf_buffer_init (&buf.base, buf.direct, array_length (buf.direct),
 			__printf_buffer_mode_asprintf);