On Tue, Apr 14, 2009 at 8:19 PM, Michael Jennings <e-de...@kainx.org> wrote:
> On Tuesday, 14 April 2009, at 18:19:57 (-0300),
> Gustavo Sverzut Barbieri wrote:
>
>>  yes, it is better, because you can know when you're not using them
>> and if you are using them without proper initialization, so you would
>> not hide a bug, possibly a segfault. See:
>>
>>    char *a;
>>    ...
>>     if (strcmp(a, "x") == 0) ... // compile warning
>>
>> now compare:
>>
>>    char *a = NULL;
>>    ...
>>     if (strcmp(a, "x") == 0) ... // silent segv
>
> The real problem here is that you're blindly dereferencing a pointer
> without checking its validity first.  And the proper way to do that is
> to initialize it to NULL first and then check for NULL before
> dereferencing.  Dereferencing a potentially invalid pointer is the
> error and will SEGV whether that pointer is NULL or not.

I can't believe you really work with software development.

Do you overcheck EVERY TIME?

char *a = NULL;
if (a && strcmp(a, "x") == 0) ...;
if (a) memcpy(b, a...)

I usually know the code that I do, or others do. I always read what's
there before changing. If others don't do it, then it's not MY fault.
I'll simply not develop C code thinking that someone might be stupid
enough... oh wait,...

-- 
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: barbi...@gmail.com
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to