Messages in this thread | ![/](/images/icornerl.gif) | | Date | Thu, 10 Jul 2003 23:00:45 +0200 | From | Dennis Bliefernicht <> | Subject | Re: Style question: Should one check for NULL pointers? |
| |
Alan Stern wrote: > On the other hand, what if on rare occasions the pointer actually is NULL, > even though it's not supposed to be? This can only be the result of an > error somewhere else in the kernel (such as incorrect locking during a > data structure update). Detecting the NULL pointer and returning an error > code will hide the existence of the true underlying error. But if the > check _isn't_ made, then as soon as the pointer is derefenced there will > be a nice big segfault. This will immediately alert people to the > existence of a problem, something they otherwise might not be aware of at > all. The problem is IMHO code where some pretty fragile things are handled, especially file systems. I'd say: DO the paranoia checks if some fragile things are involved like key structures of the file system that can take _permanent_ damage. If you check for a NULL pointer you still have the chance to properly leave the system in a consistent state and no user will be happy if his filesystem goes messy just because someone saved a check to have nicer code, even if the original of the NULL pointer wasn't his fault, even if it's a developing version. So if the check isn't a total performace disaster, do it whenever permanent damage could occur. On other sections where, let's say just a user memory allocation would crash, checks could be ommitted, because it isn't that fatal and leaves no permanent destruction.
Just my opinion :) TriPhoenix
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| ![\](/images/icornerr.gif) |