Browse Source

Check index before using

qarmin 4 years ago
parent
commit
94444cb76f
2 changed files with 3 additions and 3 deletions
  1. 1 1
      daemon/gamemode-context.c
  2. 2 2
      daemon/gamemode-tests.c

+ 1 - 1
daemon/gamemode-context.c

@@ -1006,7 +1006,7 @@ fail:
 static void game_mode_execute_scripts(char scripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX], int timeout)
 {
 	unsigned int i = 0;
-	while (*scripts[i] != '\0' && i < CONFIG_LIST_MAX) {
+	while (i < CONFIG_LIST_MAX && *scripts[i] != '\0') {
 		LOG_MSG("Executing script [%s]\n", scripts[i]);
 		int err;
 		const char *args[] = { "/bin/sh", "-c", scripts[i], NULL };

+ 2 - 2
daemon/gamemode-tests.c

@@ -370,7 +370,7 @@ static int run_custom_scripts_tests(struct GameModeConfig *config)
 
 	if (startscripts[0][0] != '\0') {
 		int i = 0;
-		while (*startscripts[i] != '\0' && i < CONFIG_LIST_MAX) {
+		while (i < CONFIG_LIST_MAX && *startscripts[i] != '\0') {
 			LOG_MSG(":::: Running start script [%s]\n", startscripts[i]);
 
 			const char *args[] = { "/bin/sh", "-c", startscripts[i], NULL };
@@ -393,7 +393,7 @@ static int run_custom_scripts_tests(struct GameModeConfig *config)
 
 	if (endscripts[0][0] != '\0') {
 		int i = 0;
-		while (*endscripts[i] != '\0' && i < CONFIG_LIST_MAX) {
+		while (i < CONFIG_LIST_MAX && *endscripts[i] != '\0') {
 			LOG_MSG(":::: Running end script [%s]\n", endscripts[i]);
 
 			const char *args[] = { "/bin/sh", "-c", endscripts[i], NULL };