Commit 6b386c16 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

x*alloc: handle zero-size allocations (fixes #19052)

parent e96bd27d
...@@ -863,26 +863,26 @@ static inline const char *vlc_pgettext_aux( const char *ctx, const char *id ) ...@@ -863,26 +863,26 @@ static inline const char *vlc_pgettext_aux( const char *ctx, const char *id )
/***************************************************************************** /*****************************************************************************
* Loosy memory allocation functions. Do not use in new code. * Loosy memory allocation functions. Do not use in new code.
*****************************************************************************/ *****************************************************************************/
static inline void *xmalloc (size_t len) static inline void *xmalloc(size_t len)
{ {
void *ptr = malloc (len); void *ptr = malloc(len);
if (unlikely (ptr == NULL)) if (unlikely(ptr == NULL && len > 0))
abort (); abort();
return ptr; return ptr;
} }
static inline void *xrealloc (void *ptr, size_t len) static inline void *xrealloc(void *ptr, size_t len)
{ {
void *nptr = realloc (ptr, len); void *nptr = realloc(ptr, len);
if (unlikely (nptr == NULL)) if (unlikely(nptr == NULL && len > 0))
abort (); abort();
return nptr; return nptr;
} }
static inline void *xcalloc (size_t n, size_t size) static inline void *xcalloc(size_t n, size_t size)
{ {
void *ptr = calloc (n, size); void *ptr = calloc(n, size);
if (unlikely (ptr == NULL)) if (unlikely(ptr == NULL && (n > 0 || size > 0)))
abort (); abort ();
return ptr; return ptr;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment