summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2021-03-16 09:38:37 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2021-03-16 09:48:51 (EDT)
commit60abe24450a8d02b0a0f85c40190f26472fb5ab8 (patch)
treedd1bda39cb5495f245dbd72bbc2673151ae1d942 /src
parentbd931017c1843f9ae24ce082ab41c43cb57428e8 (diff)
downloaddodge-balls-60abe24450a8d02b0a0f85c40190f26472fb5ab8.zip
dodge-balls-60abe24450a8d02b0a0f85c40190f26472fb5ab8.tar.gz
dodge-balls-60abe24450a8d02b0a0f85c40190f26472fb5ab8.tar.bz2
db_games_find(): Check scandir() return value
Fixes a bad calloc() if the games directory is empty or not found.
Diffstat (limited to 'src')
-rw-r--r--src/game.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/game.c b/src/game.c
index 2bf99c5..d136005 100644
--- a/src/game.c
+++ b/src/game.c
@@ -37,6 +37,12 @@ db_games_find(const char *games_dir, char ***games)
int i;
n = scandir(games_dir, &entries, &_db_game_is_dir, alphasort);
+ if (n < 0) {
+ db_err("Failed to scan games directory");
+ return -1;
+ } else if (n == 0) {
+ return 0;
+ }
*games = calloc(n, sizeof(**games));
if (*games == NULL) {