[OpenSER-Devel] null socket crash
Bogdan-Andrei Iancu
bogdan at voice-system.ro
Fri Oct 12 09:30:22 CEST 2007
Hi Henning,
Henning Westerholt wrote:
> On Friday 12 October 2007, Bogdan-Andrei Iancu wrote:
>
>> Hi Juha,
>>
>> in my opinion, the test should be done outside the function. If you call
>> the function, it means you have a valid socket to convert (almost all
>> libc function are built on this idea - like if you do a strlen() on a
>> NULL pointer, it will crash ;) ).
>>
>
> Hi Bogdan,
>
> ok, but we can it do better than the glibc. ;-)
>
It is not better or worst, it is about a proven approach about who
should check the parameters.
>
>> Also the calling code may know better if the docket pointer can be null
>> or not and to perform the proper checks (there are places where the
>> function is used to convert sockets that are known not to be null and
>> the test will be just useless).
>>
>> So, in my opinion, the test should be done in lcr module and not inside
>> the function.
>>
>
> For me socket2str is just a datatype conversation function, like we have many
> in in the core, e.g. db_str2int, that implements this check. For now the only
> code that uses this function is lcr, but this can change over time.
The function is also used from core (see socket_info.c:602) where the
check is not required as the socket is know to be valid.
>
>
> As processing power is much more cheaper than developer brains (and the
> overhead of one check is really small), its in my opinion much better to
> check this in the function, even if this is sometimes useless.
>
This is a "religious" subject and I would not get into it (just as a
point, I'm not a fan of overcoding just because hardware is getting
better - otherwise we can use java ;) )
Anyhow, I see it as a coding policy (about consistency) and not
necessary performance.
Regards,
Bogdan
More information about the Devel
mailing list