Export settings_name(), shrink the unnecessarily large static buffer, guarantee NUL termination in all cases, properly name root settings structure, and simplify.
Signed-off-by: Glenn Brown <[email protected]> --- src/core/settings.c | 17 ++++++++--------- src/include/gpxe/settings.h | 2 ++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/core/settings.c b/src/core/settings.c index 52ff0cc..062b14e 100644 --- a/src/core/settings.c +++ b/src/core/settings.c @@ -288,22 +288,21 @@ static struct settings * autovivify_child_settings ( struct settings *parent, } /** - * Return settings block name (for debug only) + * Return settings block name * * @v settings Settings block * @ret name Settings block name */ -static const char * settings_name ( struct settings *settings ) { - static char buf[64]; +const char * settings_name ( struct settings *settings ) { + static char buf[16]; char tmp[ sizeof ( buf ) ]; - int count; - - for ( count = 0 ; settings ; settings = settings->parent ) { + + for ( buf[2] = buf[0] = 0; settings ; settings = settings->parent ) { memcpy ( tmp, buf, sizeof ( tmp ) ); - snprintf ( buf, sizeof ( buf ), "%s%c%s", settings->name, - ( count++ ? '.' : '\0' ), tmp ); + snprintf ( buf, sizeof ( buf ) - 1, ".%s%s", settings->name, + tmp ); } - return ( buf + 1 ); + return ( buf + 2 ); } /** diff --git a/src/include/gpxe/settings.h b/src/include/gpxe/settings.h index 0abc322..87cb44a 100644 --- a/src/include/gpxe/settings.h +++ b/src/include/gpxe/settings.h @@ -239,6 +239,8 @@ extern int storef_setting ( struct settings *settings, extern int storef_named_setting ( const char *name, const char *value ); extern int fetchf_named_setting ( const char *name, char *buf, size_t len ); +const char * settings_name ( struct settings *settings ); + extern struct setting_type setting_type_string __setting_type; extern struct setting_type setting_type_ipv4 __setting_type; extern struct setting_type setting_type_int8 __setting_type; -- 1.7.0.4 _______________________________________________ gPXE-devel mailing list [email protected] http://etherboot.org/mailman/listinfo/gpxe-devel
