Re: [xml] Action of realloc

Date view Thread view Subject view Author view

From: Nilo S. Mismetti (nilo@mediaworks.com.br)
Date: Tue Dec 05 2000 - 18:04:12 EST


Team,

Let's end the realloc "saga". P.J. Plauger at
http://www.dinkumware.com/htm_cl/stdlib.html#realloc

says:

void *realloc(void *ptr, size_t size);

The function allocates an object of size size, possibly obtaining initial
stored values from the object whose address is ptr. It returns the address
of the new object if successful; otherwise, it returns a null pointer. You
can safely convert the return value to an object pointer of any type whose
size is not greater than size.

If ptr is not a null pointer, it must be the address of an existing object
that you first allocate by calling calloc, malloc, or realloc. If the
existing object is not larger than the newly allocated object, realloc
copies the entire existing object to the initial part of the allocated
object. (The values stored in the remainder of the object are
indeterminate.) Otherwise, the function copies only the initial part of the
existing object that fits in the allocated object. If realloc succeeds in
allocating a new object, it deallocates the existing object. Otherwise, the
existing object is left unchanged.

If ptr is a null pointer, the function does not store initial values in the
newly created object.

Based on that, on all proper implemented C-library the way to manage a
failure is the way that David Lofquist:

> pStatus = realloc(pOld, newsize);
> if (pStatus == NULL) {
> free(pOld);
> etc...
> }

Nilo

----
Message from the list xml@rpmfind.net
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@rpmfind.net


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Dec 06 2000 - 09:43:48 EST