Commit 2cc55aa0 authored by Mark Lindner's avatar Mark Lindner

fixed implementation of config_setting_lookup() to correctly return

NULL instead of the passed-in setting if the specified path was not
found
parent fa7024ba
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
2021-06-19 Mark Lindner <markl@avalon> 2021-06-19 Mark Lindner <markl@avalon>
* lib/libconfig.c - Fixed double-free of config->filenames * lib/libconfig.c - Fixed double-free of config->filenames;
fixed implementation of config_setting_lookup() to correctly return
NULL instead of the passed-in setting if the specified path was not
found
* configure.ac, lib/Makefile.am - bump version numbers * configure.ac, lib/Makefile.am - bump version numbers
2021-04-28 Mark Lindner <markl@avalon> 2021-04-28 Mark Lindner <markl@avalon>
......
...@@ -1218,7 +1218,7 @@ config_setting_t *config_setting_lookup(config_setting_t *setting, ...@@ -1218,7 +1218,7 @@ config_setting_t *config_setting_lookup(config_setting_t *setting,
const char *path) const char *path)
{ {
const char *p = path; const char *p = path;
config_setting_t *found; config_setting_t *found = setting;
for(;;) for(;;)
{ {
...@@ -1229,20 +1229,18 @@ config_setting_t *config_setting_lookup(config_setting_t *setting, ...@@ -1229,20 +1229,18 @@ config_setting_t *config_setting_lookup(config_setting_t *setting,
break; break;
if(*p == '[') if(*p == '[')
found = config_setting_get_elem(setting, atoi(++p)); found = config_setting_get_elem(found, atoi(++p));
else else
found = config_setting_get_member(setting, p); found = config_setting_get_member(found, p);
if(! found) if(! found)
break; break;
setting = found;
while(! strchr(PATH_TOKENS, *p)) while(! strchr(PATH_TOKENS, *p))
p++; p++;
} }
return(*p ? NULL : setting); return(*p || (found == setting) ? NULL : found);
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment