From c5090d91a131c67533871002759b30b03b555110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 5 Aug 2022 17:40:28 +0200 Subject: [PATCH] Return void pointer from xmalloc xmalloc is a wrapper around malloc(3), which bails out on OOM failures. As such it returns raw memory and is used to allocated all kind of types. --- lib/prototypes.h | 2 +- libmisc/xmalloc.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/prototypes.h b/lib/prototypes.h index 4e997e32..bd832f49 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -480,7 +480,7 @@ extern int setutmpx (struct utmpx *utx); extern bool valid (const char *, const struct passwd *); /* xmalloc.c */ -extern /*@maynotreturn@*/ /*@only@*//*@out@*//*@notnull@*/char *xmalloc (size_t size) +extern /*@maynotreturn@*/ /*@only@*//*@out@*//*@notnull@*/void *xmalloc (size_t size) /*@ensures MaxSet(result) == (size - 1); @*/; extern /*@maynotreturn@*/ /*@only@*//*@notnull@*/char *xstrdup (const char *); extern void xfree(void *ap); diff --git a/libmisc/xmalloc.c b/libmisc/xmalloc.c index 9329e674..25b136a4 100644 --- a/libmisc/xmalloc.c +++ b/libmisc/xmalloc.c @@ -26,11 +26,11 @@ #include "prototypes.h" #include "shadowlog.h" -/*@maynotreturn@*/ /*@only@*//*@out@*//*@notnull@*/char *xmalloc (size_t size) +/*@maynotreturn@*/ /*@only@*//*@out@*//*@notnull@*/void *xmalloc (size_t size) { - char *ptr; + void *ptr; - ptr = (char *) malloc (size); + ptr = malloc (size); if (NULL == ptr) { (void) fprintf (log_get_logfd(), _("%s: failed to allocate memory: %s\n"),