timeline: gracefullly handle out of bounds indexes in TM_GetArg

This commit is contained in:
Sebastian Krzyszkowiak 2019-03-30 04:06:40 +01:00
parent 9706f61116
commit 1e7fe215c4
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 6 additions and 2 deletions

View file

@ -26,7 +26,7 @@ static void DestroyArgs(struct TM_Arguments* args) {
}
}
SYMBOL_EXPORT struct Timeline* TM_Init(struct Game* game, struct GamestateResources* data, char* name) {
SYMBOL_EXPORT struct Timeline* TM_Init(struct Game* game, struct GamestateResources* data, const char* name) {
PrintConsole(game, "Timeline Manager[%s]: init", name);
struct Timeline* timeline = malloc(sizeof(struct Timeline));
timeline->game = game;
@ -373,8 +373,12 @@ SYMBOL_EXPORT struct TM_Arguments* TM_AddToArgs(struct TM_Arguments* args, int n
}
SYMBOL_EXPORT void* TM_GetArg(struct TM_Arguments* args, int num) {
if (!args) { return NULL; }
for (int i = 0; i < num; i++) {
args = args->next;
if (!args) {
return NULL;
}
}
return args->value;
}

View file

@ -68,7 +68,7 @@ struct TM_Action {
};
/*! \brief Init timeline. */
struct Timeline* TM_Init(struct Game* game, struct GamestateResources* data, char* name);
struct Timeline* TM_Init(struct Game* game, struct GamestateResources* data, const char* name);
/*! \brief Process current timeline actions. */
void TM_Process(struct Timeline*, double delta);