Anthony Liguori wrote:
>> Michael Tokarev wrote:
...
>>>> if (strcmp(vc->model, "tap") == 0 &&
>>>> - sscanf(vc->info_str, "ifname=%63s ", ifname) == 1 &&
>>>> + sscanf(vc->info_str, "ifname=%63s,", ifname) == 1 &&
>>
>> And while we're at it.. Why the parsing isn't done like this:
>>
>> for(tok = strtok(arg, ","); tok; tok = strtok(NULL, ",")) {
>> if (strncmp(tok, "ifname=", 7) == 0)
>> strcpy(ifname, tok+7);
>> else if ...
>> }
>
> Because strtok is extremely evil.
I didn't mean strtok, but the way -- something LIKE that, i.e,
by splitting the string into args and parsing each in turn.
There's getsubopt(3) too, which does exactly that, and which
is used by, say, mount(8) to parse mount options (-o foo=bar
things). Those home-grown sscanfs tend to become buggy like
in this example...
And if you dislike strtok especially, there are other alternatives.
And speaking of strtok, there's nothing evil in it provided you
don't run another strtok sequence while this one is running
(it's not reenterant, so to say). Here, let it modify the
existing string and replace delimiters with zeros to terminate
our tokens, -- nothing wrong with that. It's not worse than
silently truncating ifname size to 63 chars first and to
IF_NAMESIZE second. If you don't want to modify original
string, strdup() or astrdup() are our friends... But that's
all details, details, not related to the original issue and
question.
/mjt
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html