Re: Extra bytes
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Thu, 16 Oct 2008 16:55:02 -0400
eb_csilva wrote:
[...]
And Eric,
"In case that ptr is NULL, the [realloc] function behaves exactly as
malloc, assigning a new block of size bytes and returning a pointer to
the beginning of it." (from cplusplus.com)
"The realloc function changes the size of an allocated memory block.
The memblock argument points to the beginning of the memory block. If
memblock is NULL, realloc behaves the same way as malloc and allocates
a new block of size bytes. If memblock is not NULL, it should be a
pointer returned by a previous call to calloc, malloc, or
realloc." (from microsoft.com).
Are you telling me that this behaviour can be platform-dependent or
vendor-dependent?
No, there was nothing wrong with your use of realloc (except that
you didn't compare the returned value to NULL to check for failure).
I was trying to tell you that what your filled the allocated memory
with wasn't a string, and that its non-stringness could explain the
presence of the extra characters. I also pointed you at some library
functions that could replace a good deal of your code.
I don't understand your comment "debug a paraphrase". This is my
production code, from which I stripped out some irrellevant (in my
opinion) details.
The fact that a pointer was initialized to `null' and later
compared to `NULL' led me to suspect otherwise. It is, of course,
perfectly legal to define your own `null' macro or to create a
pointer variable named `null' with the value `NULL', but it seems
a strange thing to do. But if you say so ...
Also, since the problem at hand is extra characters in the
printed output, stripping out the code that printed the output
may not have been the very best choice.
--
Eric.Sosman@xxxxxxx
.
- Follow-Ups:
- Re: Extra bytes
- From: Martin Vuille
- Re: Extra bytes
- References:
- Extra bytes
- From: eb_csilva
- Re: Extra bytes
- From: mman
- Re: Extra bytes
- From: eb_csilva
- Re: Extra bytes
- From: Eric Sosman
- Re: Extra bytes
- From: Moi
- Re: Extra bytes
- From: eb_csilva
- Extra bytes
- Prev by Date: Re: Extra bytes
- Next by Date: Re: Extra bytes
- Previous by thread: Re: Extra bytes
- Next by thread: Re: Extra bytes
- Index(es):
Relevant Pages
|