Fun with NULL pointers, part 2
Fun with NULL pointers, part 2
Posted Jul 21, 2009 21:35 UTC (Tue) by i3839 (guest, #31386)Parent article: Fun with NULL pointers, part 2
>
> If we dereference NULL then the kernel will display basically the same
> information as would a BUG, and it takes the same action. So adding a
> BUG_ON here really doesn't gain us anything.
>
> This reasoning is based on the idea that dereferencing a NULL pointer
> will cause a kernel oops.
For the Smack example, if you read the code it's clear that the BUG_ON check makes no sense. It is in a static function and all callers either check or dereference the pointer. More generically, adding BUG_ONs everywhere for pointers that shouldn't be NULL is the wrong approach: Either make sure that all callers don't pass in a NULL pointer, or if that isn't possible, add a check and return with an error.
For the other example the kernel better make that it notices it when it's NULL, one way or the other.
