Re: Testing on NULL an unitialized values

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

 



On 04/22/2010 03:54 AM, Marc Lehmann wrote:
> On Wed, Apr 21, 2010 at 08:14:33PM +0200, Martin Nordholts<enselic@xxxxxxxxx>  wrote:
>> The compiler doesn't catch all cases, like this one:
>>
>> #include<stdio.h>
>> int main(int argc, char **argv)
>> {
>>     int var;
>>     if (argc == 2)
>>       var = 42;
>>     printf ("var = %d", var);
>>     return 0;
>> }
>
> 1. initialising var will not fix the bug, if there is any.

It won't, but it will make the bug consistently occur, which is a big plus.


> 2. initialising var will prevent other static analysers
>     to diagnose a possible problem.

The problem to diagnose would be that of using an initialized variable, 
no? The fix would then be to initialize the variable.


> 3. initialising var will prevent "weird effects"
>     and just *might* decrease chances of finding the bug further.

Why would you want "weird effects" in software? That's exactly what you 
don't want. At worst, a bug should manifest itself by making a program 
not do what it was intended to do, not doing something unpredictable.


>> Since use of uninitlized variables very well can cause severe and
>> hard-to-reproduce crashes, and since unpredictability never is a good
>
> Actually, it's easy to diagnose those bugs though, just look at the
> coredump.

The coredump gives you the state of the program when it crashed, not the 
cause leading up to the crash, which could have been an uninitlized 
local variable that's no longer in any stack frame.


> Yes, don't do it unnecessarily, it tends to hide bugs.

Rather "As a rule of thumb, initialize local variables.". As always 
there are cases where it's better not to initialize local variables.

  / Martin
_______________________________________________
Gimp-developer mailing list
Gimp-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux