Re: Access violation in free()



Richard wrote:

Tor Rustad <tor_rustad@xxxxxxxxxxx> writes:

I consider this better:

assert(NULL != s);

before calling strlen().

I have known solid, calm programmers go barmy when confronted with
these asserts. They are generally NOT required and only contribute
noise IMO.

Sure there might be a few cases such as initial string allocation but
generally I find ASSERTS everywhere indicative of bad design. A good
design KNOWS that these things are not null in most cases. Too many
times they are just thrown in haphazardly as a "cure all" for poor
design.

IME, asserts are typically used to protect the code against users
(programmers!) that can't read documentation.
The assert is there to indicate as early as possible that the code is
being abused.
I strongly prefer an assert over having the code produce UB. Having
probems pointed out early in the integration testing beats having
management breathing down your neck because the end-users found a
problem that appears to stem from your code (but is actually caused by
someone incorrectly using your code).

Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
.



Relevant Pages

  • Re: problem with AfxMessageBox in a thread in a dll
    ... under normal operating conditions is a bad design. ... that ASSERTs are handled by a low-level::MessageBox call, which although risky is not as ... low-level socket work a message pump isn't relevant to the discussion. ... falling apart horribly before you can start debugging it. ...
    (microsoft.public.vc.mfc)
  • Re: Access violation in free()
    ... these programmers have never developed code for safety-critical applications and gone through an external code audit. ... generally I find ASSERTS everywhere indicative of bad design. ...
    (comp.lang.c)
  • Re: How to disprove Intelligent Design
    ... > ID asserts it is possible to identify "characteristics of intelligent ... > design" that only occur in objects designed by intelligence. ... ID is exactly used to invoke whenever science lacks a complete ... > unintelligent causes then it must, by definition, lack characteristics of ...
    (talk.origins)
  • Re: [patch 1/3] add basic accounting fields to taskstats
    ... Balbir Singh wrote: ... More majordomo info at http://vger.kernel.org/majordomo-info.html ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)
  • Re: [Bug #13375] Kernel crash with 2.6.29 + nfs + xfs (radix-tree)
    ... kinds of asserts might trigger? ... How much of a slowdown are we likely talking about? ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)