Re: malloc realloc and pointers




"K. Jennings" <kjennings@xxxxxxxxxxxxxx> wrote in message
news:pan.2007.11.30.03.44.02@xxxxxxxxxxxxxxxxx
On Thu, 29 Nov 2007 17:00:05 -0500, Kenneth Brody wrote:

ravi wrote:
2. With realloc(), if some pointer 'ptr' is pointing initially to a
perticular position in a buffer (char *buffer) then on performing a
realloc() on this buffer, what will be 'ptr' pointing to?

Three possibilities:

1) realloc() returns the same pointer, in which case ptr is still
valid, pointing to the newly-sized buffer.

2) realloc() returns a different pointer, in which case ptr is
no longer valid, and must not be dereferenced.

3) realloc() returns NULL, in which case ptr is pointing to the
unchanged memory region as before.

What happens when ptr is not one returned by a previous
invocation to malloc(), calloc() or realloc()?


then, if you are the program, ninjas run up, kick you somewhere painful, and
insert a corncob somewhere painful.
one then has to try to hobble off to the bathroom for a 'core dump'...



.



Relevant Pages

  • Re: malloc realloc and pointers
    ... perticular position in a buffer then on performing a ... realloc() returns the same pointer, in which case ptr is still ... pointer is identical to the old pointer, you're not allowed to use them ...
    (comp.lang.c)
  • Re: malloc realloc and pointers
    ... perticular position in a buffer then on performing a ... realloc() returns the same pointer, in which case ptr is still ... pointing to the newly-sized buffer. ...
    (comp.lang.c)
  • Re: malloc realloc and pointers
    ... in which case ptr is pointing to the ... unchanged memory region as before. ... What happens when ptr is not one returned by a previous ... Then you know that realloc moved the storage. ...
    (comp.lang.c)
  • Re: Buffer or Realloc?
    ... better to allocate memory and realloc it for the size of the what is ... between deciding to use a fixed size buffer or allocating memory ... Fixed size arrays are good for things that whose contents *CANNOT* ... becomes extremely small when I realloc it. ...
    (comp.lang.c)
  • Re: openssh vulnerability
    ... > second value to realloc). ... call clean-up functions, and apparently one of those clean-up ... functions may call buffer_free() on that same buffer that's in ... talking about writing nulls... ...
    (Vuln-Dev)