Make parse_list() a bit stricter by only allowing items to be skipped if they are explicitly marked with - e.g %V|0|0|-|-|1|-|-|

it will now error out if a - is missing and the item wasnt read properly


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17697 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jonathan Gordon 2008-06-07 08:30:06 +00:00
parent 4bbdc5c3a3
commit cbbbaac650

View file

@ -1220,6 +1220,7 @@ int hex_to_rgb(const char* hex, int* color)
valid_vals - if not NULL 1 is set in the bitplace if the item was read OK valid_vals - if not NULL 1 is set in the bitplace if the item was read OK
0 if not read. 0 if not read.
first item is LSB, (max 32 items! ) first item is LSB, (max 32 items! )
Stops parseing if an item is invalid unless the item == '-'
sep - list separator (e.g. ',' or '|') sep - list separator (e.g. ',' or '|')
str - string to parse, must be terminated by 0 or sep str - string to parse, must be terminated by 0 or sep
... - pointers to store the parsed values ... - pointers to store the parsed values
@ -1262,14 +1263,14 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
*s = p; *s = p;
while (*p && *p != sep) while (*p && *p != sep)
p++; p++;
valid = (*s[0]!=sep); valid = (*s[0]!='-') && (*s[1]!=sep) ;
break; break;
case 'd': /* int */ case 'd': /* int */
d = va_arg(ap, int*); d = va_arg(ap, int*);
if (!isdigit(*p)) if (!isdigit(*p))
{ {
if (!valid_vals) if (!valid_vals || *p != '-')
goto err; goto err;
while (*p && *p != sep) while (*p && *p != sep)
p++; p++;
@ -1290,7 +1291,7 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
if (hex_to_rgb(p, d) < 0) if (hex_to_rgb(p, d) < 0)
{ {
if (!valid_vals) if (!valid_vals || *p != '-')
goto err; goto err;
while (*p && *p != sep) while (*p && *p != sep)
p++; p++;
@ -1313,7 +1314,7 @@ const char* parse_list(const char *fmt, unsigned int *valid_vals,
*d = *p++ - '0'; *d = *p++ - '0';
valid = true; valid = true;
} }
else if (!valid_vals) else if (!valid_vals || *p != '-')
goto err; goto err;
else else
{ {