Quote:
Originally Posted by win32sux
(Post 3611965)
What I find amazing is the role which the compiler plays in this.
|
It is an interesting one isn't it. Though to be fair to the compiler, it looks like bad code caused it to make a bad decision.
Here's the code in question:
Code:
struct sock *sk = tun->sk; // initialize sk with tun->sk
if (!tun)
return POLLERR; // if tun is NULL return error
If there's a possibility of tun being NULL then initialising *sk from it before checking for NULL is clearly a dubious operation regardless of whether you check it afterwards.
Surely it's common sense that you should check it before you use it.
Code:
if (!tun)
return POLLERR; // if tun is NULL return error
struct sock *sk = tun->sk; // initialize sk with tun->sk
But then, I'm just a novice C coder, so I may be missing something in the details.
|