timestamp_before_wait might be used uninitialized in this function
walter harms
wharms at bfs.de
Wed Jan 14 13:21:47 UTC 2009
Denys Vlasenko schrieb:
> On Tuesday 13 January 2009 19:21, walter harms wrote:
>> Cristian Ionescu-Idbohrn schrieb:
>>> I see this warning, and I don't like it:
>>>
>>> busybox-1.13.2/networking/udhcp/dhcpc.c:
>>> In function `udhcpc_main':
>>> busybox-1.13.2/networking/udhcp/dhcpc.c:321:
>>> warning: `timestamp_before_wait' might be used uninitialized in this function
>>>
>>> Is this patch appropriate?
>>>
>>> --- busybox-1.13.2/networking/udhcp/dhcpc.c.~1~ 2008-11-09 18:27:58.000000000 +0100
>>> +++ busybox-1.13.2/networking/udhcp/dhcpc.c 2009-01-13 13:09:30.000000000 +0100
>>> @@ -342,7 +342,8 @@
>>> /* Else: an error occured, panic! */
>>> bb_perror_msg_and_die("select");
>>> }
>>> - }
>>> + } else
>>> + timestamp_before_wait = 0;
>>>
>>> /* If timeout dropped to zero, time to become active:
>>> * resend discover/renew/whatever
>>>
>>>
>>> Cheers,
>>>
>> maybe a simple
>> unsigned timestamp_before_wait=0;
>>
>> will do the same ?
>
> Yes. but
>
> unsigned timestamp_before_wait = timestamp_before_wait;
>
> is better wrt code size. :)
>
> fixed. thanks.
>
aehm, that will only fool the compiler to thing it is used.
timestamp_before_wait=0 will make sure that it works even if the 'if (tv.tv_sec > 0)' fails.
and it will fail because:
timeout = 0;
already_waited_sec = 0;
...
tv.tv_sec = timeout - already_waited_sec;
if (tv.tv_sec > 0)
timestamp_before_wait = (unsigned)monotonic_sec();
...
already_waited_sec += (unsigned)monotonic_sec() - timestamp_before_wait;
>> btw: can unsigned be replaced with unsigned int or whatever is useful here ?
>
> ?! "unsigned" and "unsigned int" are the same.
this is true. a compiler has no problems but i prefer clear types.
More information about the busybox
mailing list