From 6467673e06e95d434df408b365b7ec7988a2c9f6 Mon Sep 17 00:00:00 2001 From: "p.kosyh" Date: Tue, 19 Jan 2010 07:48:53 +0000 Subject: [PATCH] checking for empty slot name and game name --- src/sdl-instead/game.c | 7 +++++-- src/sdl-instead/menu.c | 7 +++++-- src/sdl-instead/util.c | 9 +++++++++ src/sdl-instead/util.h | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/sdl-instead/game.c b/src/sdl-instead/game.c index a8ce8ea..4a1e44e 100644 --- a/src/sdl-instead/game.c +++ b/src/sdl-instead/game.c @@ -92,8 +92,11 @@ static char *game_name(const char *path, const char *d_name) goto err; l = lookup_tag(p, "Name", "--"); free(p); - if (l) - return l; + if (l) { + if (!is_empty(l)) + return l; + free(l); + } err: return strdup(d_name); } diff --git a/src/sdl-instead/menu.c b/src/sdl-instead/menu.c index e17c797..0670389 100644 --- a/src/sdl-instead/menu.c +++ b/src/sdl-instead/menu.c @@ -51,9 +51,12 @@ static char *slot_name(const char *path) FILE *fd; l = lookup_tag(path, "Name", "--"); if (l) { - char *s = fromgame(l); + if (!is_empty(l)) { + char *s = fromgame(l); + free(l); + return s; + } free(l); - return s; } fd = fopen(path, "r"); if (!fd) diff --git a/src/sdl-instead/util.c b/src/sdl-instead/util.c index f7171e3..158988a 100644 --- a/src/sdl-instead/util.c +++ b/src/sdl-instead/util.c @@ -27,6 +27,15 @@ int is_space(int c) return (c == ' ' || c == '\t'); } +int is_empty(const char *str) +{ + if (!str || !*str) + return 1; + while (*str && !is_space(*str++)) + return 0; + return 1; +} + char *strip(char *s) { char *e; diff --git a/src/sdl-instead/util.h b/src/sdl-instead/util.h index ea7ee67..921b476 100644 --- a/src/sdl-instead/util.h +++ b/src/sdl-instead/util.h @@ -10,6 +10,8 @@ struct parser { }; extern int is_space(int c); +extern int is_empty(const char *str); + extern int parse_ini(const char *path, struct parser *cmd_parser); extern char *getpath(const char *d, const char *n); extern char *strip(char *s);