Skip to content

Commit 688691b

Browse files
committed
Don't access null pointers when printing null module names
fixes wren-lang#631
1 parent 7eac8e6 commit 688691b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/vm/wren_compiler.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,18 +393,21 @@ static void printError(Parser* parser, int line, const char* label,
393393
{
394394
parser->hasError = true;
395395
if (!parser->printErrors) return;
396-
396+
397397
// Only report errors if there is a WrenErrorFn to handle them.
398398
if (parser->vm->config.errorFn == NULL) return;
399-
399+
400400
// Format the label and message.
401401
char message[ERROR_MESSAGE_SIZE];
402402
int length = sprintf(message, "%s: ", label);
403403
length += vsprintf(message + length, format, args);
404404
ASSERT(length < ERROR_MESSAGE_SIZE, "Error should not exceed buffer.");
405-
405+
406+
ObjString* module = parser->module->name;
407+
const char* module_name = module ? module->value : "<unknown>";
408+
406409
parser->vm->config.errorFn(parser->vm, WREN_ERROR_COMPILE,
407-
parser->module->name->value, line, message);
410+
module_name, line, message);
408411
}
409412

410413
// Outputs a lexical error.

0 commit comments

Comments
 (0)