From: Michael Tokarev <mjt@tls.msk.ru>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Mark McLoughlin <markmc@redhat.com>,
John Wong <johnw@wonghome.net>, Avi Kivity <avi@redhat.com>,
KVM list <kvm@vger.kernel.org>
Subject: Re: [ANNOUNCE] kvm-83 release
Date: Wed, 14 Jan 2009 00:01:04 +0300 [thread overview]
Message-ID: <496D0110.2020200@msgid.tls.msk.ru> (raw)
In-Reply-To: <496CFB8E.1060407@codemonkey.ws>
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
next prev parent reply other threads:[~2009-01-13 21:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-13 13:53 [ANNOUNCE] kvm-83 release Avi Kivity
2009-01-13 15:54 ` Farkas Levente
2009-01-15 14:00 ` Avi Kivity
2009-01-15 20:17 ` Farkas Levente
2009-01-13 16:15 ` John Wong
2009-01-13 17:27 ` Mark McLoughlin
2009-01-13 17:40 ` John Wong
2009-01-13 18:22 ` Amit Shah
2009-01-13 20:32 ` Michael Tokarev
2009-01-13 20:35 ` Michael Tokarev
2009-01-13 20:37 ` Anthony Liguori
2009-01-13 21:01 ` Michael Tokarev [this message]
2009-01-13 22:30 ` Mark McLoughlin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=496D0110.2020200@msgid.tls.msk.ru \
--to=mjt@tls.msk.ru \
--cc=anthony@codemonkey.ws \
--cc=avi@redhat.com \
--cc=johnw@wonghome.net \
--cc=kvm@vger.kernel.org \
--cc=markmc@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox