[Swan] strncpy doesn't do what many people think that it does

Wes Hardaker opensource at hardakers.net
Fri Feb 15 19:33:34 EET 2013


"D. Hugh Redelmeier" <hugh at mimosa.com> writes:

> assert_or_return: why not just warn AND return (or more accurately:
> apologize and return)?  If return is going to work, why crash?  (You
> might want a separate abort-on-apology setting.)

We do.  We log a warning, optionally with an extra message and then
return an error code.  But for "developer mode" it goes to a real assert
instead so if you can reproduce it, you can run it in a debugger and
have it crash and have the full stack to play with.  IE, the
compile-time switch between don't-ever-crash and crash-for developer
(./configure --enable-developer) is highly useful.

> How is assert_or_msgreturn conceptually different from
> assert_or_return?

  printf("assert hit");
  printf(passed_in_message);
  return passed_in_value;

Here's the full definition list:

http://www.net-snmp.org/dev/agent/snmp__assert_8h_source.html

> Quick question: do you like architectures that SEGFAULT on
> dereferencing NULL, or ones that silently access memory at address 0?
> I made hardware and OS mods to a computer I owned to move it to the
> SEGFAULT class: that's how strong my preference is.  Assertions are
> like that.

I like functions that check for NULLs and pass the buck instead of
trying to read it.
-- 
Wes Hardaker                                     
My Pictures:  http://capturedonearth.com/
My Thoughts:  http://pontifications.hardakers.net/


More information about the Swan mailing list