[Ovirt-devel] Re: ovirt-listen-awake
Chris Lalancette
clalance at redhat.com
Wed Oct 15 15:07:17 UTC 2008
Dan Kenigsberg wrote:
>>> @@ -37,14 +37,7 @@
>>>
>>> static int streq(char *first, char *second)
>>> {
>>> - int first_len, second_len;
>>> -
>>> - first_len = strlen(first);
>>> - second_len = strlen(second);
>>> -
>>> - if (first_len == second_len && strncmp(first, second, first_len) == 0)
>>> - return 1;
>>> - return 0;
>>> + return !strcmp(first, second);
>>> }
>> Heh. Well, the idea was that I wanted to be a little more defensive, so that
>> "IDENTIFY" != "IDENTIFYFOO" (or whatever). I could have sworn I've run into
>> bugs doing that in the past, but a quick test shows that strcmp() properly
>> returns failure in that case.
>>
>> Ah, now I remember. I was taught always to use strncmp(), and just doing
>> strncmp(first, second, strlen(first)) runs into the bug I was trying to avoid.
>
> My point is that your
> first_len = strlen(first);second_len = strlen(second);strncmp(first, second, first_len)
> runs into that bug, too...
Ah, but it doesn't, because of the first_len == second_len guard.
--
Chris Lalancette
More information about the ovirt-devel
mailing list