From 0a679d794a89ae205c8580ab9e8369af78b192ad Mon Sep 17 00:00:00 2001 From: Peter0x44 Date: Thu, 20 Oct 2022 15:48:35 +0100 Subject: [PATCH] parser: Fail gracefully if a nonexistent file is passed on the command line Before, if a nonexistent file was passed to LoadFileText(), it would return NULL, and the parser would happily dereference it. --- parser/raylib_parser.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/parser/raylib_parser.c b/parser/raylib_parser.c index 49b43f768..5ca186d71 100644 --- a/parser/raylib_parser.c +++ b/parser/raylib_parser.c @@ -207,6 +207,12 @@ int main(int argc, char* argv[]) int length = 0; char *buffer = LoadFileText(inFileName, &length); + if (buffer == NULL) + { + printf("Could not read input file: %s\n", inFileName); + return 1; + } + // Preprocess buffer to get separate lines // NOTE: GetTextLines() also removes leading spaces/tabs int linesCount = 0;