Re: Access violation in free()
- From: Bart van Ingen Schenau <bart@xxxxxxxxxxxxxxx>
- Date: Sun, 02 Sep 2007 22:18:32 +0200
Richard wrote:
Tor Rustad <tor_rustad@xxxxxxxxxxx> writes:IME, asserts are typically used to protect the code against users
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.
(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/
.
- References:
- Access violation in free()
- From: spl
- Re: Access violation in free()
- From: Martin Ambuhl
- Re: Access violation in free()
- From: Richard Heathfield
- Re: Access violation in free()
- From: Tor Rustad
- Re: Access violation in free()
- From: Richard
- Access violation in free()
- Prev by Date: Re: Access violation in free()
- Next by Date: Re: Default values for arguments
- Previous by thread: Re: Access violation in free()
- Next by thread: Re: Access violation in free()
- Index(es):
Relevant Pages
|