Garrett D'Amore writes:
> > 28821         ipst = ns->netstack_ip;
> > 28822         ASSERT(ipst != NULL);
> > 28823 
> > 28824         ipst->ips_ip_cgtp_filter_ops = ops;
[...]
> 2) It provides better debug information when the programmer has made a
> mistake.  (The panic message and point of panic will be at the point of
> assertion, rather than later in the code, which might be harder to
> debug.)

In this case, I'd argue that this is an unnecessary assertion.

If the pointer were null, counter to the assertion, then we'd panic
anyway at 28824, and the panic would be _obvious_.  It'd be a "null
pointer dereference" panic, and something that's trivial to diagnose
with just a little effort.

Thus, the ASSERT here adds no real value and shouldn't appear.

Assertions *should* be used to validate design constraints that are
hard to detect otherwise, such as a missing flag or state that will
lead to trouble much further down the line, not something that'll fail
in an obvious way on the very next line of code.

If it helps, you can think of every pointer dereference as having an
implicit pointer value check and assertion.  This checks not just the
single special value NULL, but also pointers that reference unmapped
pages.

-- 
James Carlson, Solaris Networking              <[EMAIL PROTECTED]>
Sun Microsystems / 1 Network Drive         71.232W   Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757   42.496N   Fax +1 781 442 1677
_______________________________________________
networking-discuss mailing list
[email protected]

Reply via email to