diff --git a/src/strutil.c b/src/strutil.c index fcb12232..36c02281 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -241,9 +241,19 @@ int str_is_in_list(const char *s, const char **l, size_t nl, int (*f)(const char return 0; } +// Is the string a decimal bus/device number that ends in a colon or nul? +static int is_busdev_num(const char *s) { + const char *t = s; + + while(*t >= '0' && *t <= '9') + t++; + + return t > s && (*t == ':' || *t == 0); +} + // Do the two strings represent the same decimal number or are they the same up to a limiting colon? int str_busdev_eq(const char *s, const char *t) { - if(*s >= '0' && *s <='9' && *t >= '0' && *t <='9') // Both look like a decimal number + if(is_busdev_num(s) && is_busdev_num(t)) if(strtoull(s, NULL, 10) == strtoull(t, NULL, 10)) return 1;