From e13243d9267c61283342f2a41923e93c933795a4 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 28 Nov 2015 15:04:11 +0000 Subject: [PATCH] NULL pointer check on scripts. --- src/battle/script.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/battle/script.c b/src/battle/script.c index 1420443..c6dbf26 100644 --- a/src/battle/script.c +++ b/src/battle/script.c @@ -73,32 +73,35 @@ void runScriptFunction(const char *format, ...) char funcNameBuffer[MAX_NAME_LENGTH]; va_list args; - memset(&funcNameBuffer, '\0', sizeof(funcNameBuffer)); - - va_start(args, format); - vsprintf(funcNameBuffer, format, args); - va_end(args); - - function = scriptJSON->child; - - while (function) + if (scriptJSON) { - functionName = cJSON_GetObjectItem(function, "function")->valuestring; + memset(&funcNameBuffer, '\0', sizeof(funcNameBuffer)); + + va_start(args, format); + vsprintf(funcNameBuffer, format, args); + va_end(args); - if (strcmp(functionName, funcNameBuffer) == 0) + function = scriptJSON->child; + + while (function) { - scriptRunner = malloc(sizeof(ScriptRunner)); - memset(scriptRunner, 0, sizeof(ScriptRunner)); + functionName = cJSON_GetObjectItem(function, "function")->valuestring; - scriptRunner->line = cJSON_GetObjectItem(function, "lines")->child; + if (strcmp(functionName, funcNameBuffer) == 0) + { + scriptRunner = malloc(sizeof(ScriptRunner)); + memset(scriptRunner, 0, sizeof(ScriptRunner)); + + scriptRunner->line = cJSON_GetObjectItem(function, "lines")->child; + + tail->next = scriptRunner; + tail = scriptRunner; + + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Running script '%s'", funcNameBuffer); + } - tail->next = scriptRunner; - tail = scriptRunner; - - SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Running script '%s'", funcNameBuffer); + function = function->next; } - - function = function->next; } }