settings: Make print_key() not rely on null-terminated beginning of key buffer

The key to print (e.g. until the next .) still has to be
null-terminated.
This commit is contained in:
Tobias Brunner
2014-02-12 14:34:32 +01:00
parent 24d2bb7793
commit ef72d4cc3f
+5 -10
View File
@@ -184,17 +184,16 @@ static bool kv_find(kv_t *this, char *key)
static bool print_key(char *buf, int len, char *start, char *key, va_list args)
{
va_list copy;
char *pos = start;
bool res;
char *pos;
va_copy(copy, args);
while (start < key)
while (TRUE)
{
pos = strchr(start, '%');
pos = memchr(pos, '%', key - pos);
if (!pos)
{
start += strlen(start) + 1;
continue;
break;
}
pos++;
switch (*pos)
@@ -215,11 +214,7 @@ static bool print_key(char *buf, int len, char *start, char *key, va_list args)
DBG1(DBG_CFG, "settings with %%%c not supported!", *pos);
break;
}
start = pos;
if (*start)
{
start++;
}
pos++;
}
res = vsnprintf(buf, len, key, copy) < len;
va_end(copy);