summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
4d78228)
Using `%zu' for the size_t value. That might be a problem on older
platforms, but we'll see. If asked for zero bytes then free an existing
pointer, only passing it to free(3) if it's non-NULL, and then allocate
a byte so a unique pointer is returned.
/* Call malloc(3), exiting on NULL return. */
void *mh_xmalloc(size_t);
/* Call malloc(3), exiting on NULL return. */
void *mh_xmalloc(size_t);
+/* Call realloc(3), exiting on NULL return. */
void *mh_xrealloc(void *, size_t);
void *mh_xrealloc(void *, size_t);
void *mh_xcalloc(size_t, size_t);
char *pwd(void);
char *add(const char *, char *);
void *mh_xcalloc(size_t, size_t);
char *pwd(void);
char *add(const char *, char *);
-/*
- * Safely call realloc
- */
-void *
-mh_xrealloc(void *ptr, size_t size)
+/* Call realloc(3), exiting on NULL return. */
+void *mh_xrealloc(void *ptr, size_t size)
- /* Some non-POSIX realloc()s don't cope with realloc(NULL,sz) */
+ /* Copy POSIX behaviour, coping with non-POSIX systems. */
+ if (size == 0) {
+ if (ptr) {
+ free(ptr);
+ }
+ return mh_xmalloc(1); /* Get a unique pointer. */
+ }
if (!ptr)
return mh_xmalloc(size);
if (!ptr)
return mh_xmalloc(size);
- if (size == 0)
- adios(NULL, "Tried to realloc 0 bytes");
-
- memory = realloc(ptr, size);
- if (!memory)
- adios(NULL, "Realloc failed");
+ new = realloc(ptr, size);
+ if (!new)
+ adios(NULL, "realloc failed, size wanted: %zu", size);