Re: parent (GUdevDevice) uninitialized in _update_s390_subchannels



Le 05/11/2010 11:15, Marc Herbert a écrit :
>>> `nm-device-ethernet.c
>>> cc1: warnings being treated as errors
>>> nm-device-ethernet.c: In function ‘constructor’:
>>> nm-device-ethernet.c:400:5: error: ‘parent’ may be used uninitialized in
>>> this function
>>
>> Attached is the patch I applied:
>>
>> -	GUdevDevice *parent;
>> +	GUdevDevice *parent = NULL; // disable gcc warning because...?
>>
>>
>> This just buries the warning. Are you sure the warning is wrong? If yes it deserves a comment.

This gcc warning is actually very good: it shows a bug! Maybe even a
crash.  The bug is triggered when
g_udev_client_query_by_subsystem_and_name() returns NULL.

I did not really look at the code and missed the "goto"s, thanks
Mathieu for correcting me.


> The proper way to get rid of this warning is not to group
> declarations at the top of the block:
> <http://stackoverflow.com/questions/288441/variable-declaration-placement-in-c/4105334#4105334>

... and doing this puts the bug in a much brighter light: it makes gcc stop
on the initialization error instead of printing a mild warning.


The ideal code would look like this:
     ....
out1:
	g_object_unref (parent);
out2:
	g_object_unref (dev);
out3:
	g_object_unref (client);
}

But Mathieu's bug fix is a bit less intrusive and probably good enough.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]