From 688691b17c4dfdb92c65ed249791deeaed3a12e7 Mon Sep 17 00:00:00 2001 From: underscorediscovery Date: Wed, 18 Sep 2019 22:49:01 -0700 Subject: [PATCH] Don't access null pointers when printing null module names fixes #631 --- src/vm/wren_compiler.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/vm/wren_compiler.c b/src/vm/wren_compiler.c index 19dfe133..6c90f1ea 100644 --- a/src/vm/wren_compiler.c +++ b/src/vm/wren_compiler.c @@ -393,18 +393,21 @@ static void printError(Parser* parser, int line, const char* label, { parser->hasError = true; if (!parser->printErrors) return; - + // Only report errors if there is a WrenErrorFn to handle them. if (parser->vm->config.errorFn == NULL) return; - + // Format the label and message. char message[ERROR_MESSAGE_SIZE]; int length = sprintf(message, "%s: ", label); length += vsprintf(message + length, format, args); ASSERT(length < ERROR_MESSAGE_SIZE, "Error should not exceed buffer."); - + + ObjString* module = parser->module->name; + const char* module_name = module ? module->value : ""; + parser->vm->config.errorFn(parser->vm, WREN_ERROR_COMPILE, - parser->module->name->value, line, message); + module_name, line, message); } // Outputs a lexical error.