foxygit / doom Log in
commit 75bedca7fb08240bc28a6cd6f7f0604231b5a403
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Sat Sep 2 19:02:54 2017 -0400
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Sat Sep 2 19:02:54 2017 -0400

    textscreen: Check return value from realloc().

    This fixes a static analysis warning detected in #939. Thanks to
    @turol for finding this.
---
 textscreen/txt_fileselect.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/textscreen/txt_fileselect.c b/textscreen/txt_fileselect.c
index 371a4065..6f6332a3 100644
--- a/textscreen/txt_fileselect.c
+++ b/textscreen/txt_fileselect.c
@@ -101,7 +101,12 @@ static char *ExecReadOutput(char **argv)
         }
         else
         {
-            result = realloc(result, result_len + bytes + 1);
+            char *new_result = realloc(result, result_len + bytes + 1);
+            if (new_result == NULL)
+            {
+                break;
+            }
+            result = new_result;
             memcpy(result + result_len, buf, bytes);
             result_len += bytes;
             result[result_len] = '\0';