I see that strcmp does not crash when NULL is passed as an argument.
But the same stuff , if the same NULL argument is being passed from the return value of a function.
Please see the below code snippet.
Hi Easton,
Sorry for not using code blocks. Here temp is not null. temp is a valid object.
Peter87,
Is the strcmp's behavior undefined for NULL parameter? Further In my actual code strcmp has been used at thousands of places. I can put a NULL check at each of the strcmp call. It will be better to resolve the crash. But it would also have a performance impact.
OR
is it the fact that we should put null check when strcmp's arguments are actually function calls. There we would put a check and in cases where the address is directly passed to strcmp, then we do not need a check.
i.e. strcmp(ptr1,ptr2) is fine.
but strcmp(f(),g()) should be
if (f() && g()) {
strcmp(f(),g())
}