Re: Access violation in free()
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Sun, 02 Sep 2007 17:35:09 +0000
Tor Rustad said:
Richard Heathfield wrote:
Martin Ambuhl said:
<snip>
Try the following and see if you have better luck:<snip>
char *CopyString(char *s)
Better: char *CopyString(const char *s)
{
int length = strlen(s);
Better: size_t length = strlen(s);
I consider this better:
assert(NULL != s);
before calling strlen().
Sure. I should have mentioned that.
<snip>
Unless you are writing e.g. a non-stop server (or a library for it,
kernel mode code etc.), the normally best thing to do on memory
failures, is simply to exit.
We've had this debate over and over, and I think it's fair to say that
the balance of expert opinion is against you (although it's far from
unanimous), although of course it does depend very much on what you're
writing (as you suggest). The consensus seems to be that, if you're
writing 'generic' code - code that you expect to be used many times by
many programs - then you should report errors rather than terminate the
program. If you're writing the program itself, however, then of course
you do whatever is the right thing for that program. But if my word
processor exit()ed on a memory allocation failure without at least
giving me the chance to save the last twenty minutes' typing, I'd be
looking for a new word processor.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.
- Follow-Ups:
- Re: Access violation in free()
- From: Tor Rustad
- Re: Access violation in free()
- 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
- Access violation in free()
- Prev by Date: Re: Malcolm's new book - Chapter 1 review
- Next by Date: Re: Malcolm's new book - Chapter 1 review
- Previous by thread: Re: Access violation in free()
- Next by thread: Re: Access violation in free()
- Index(es):
Relevant Pages
|