commit c0faa64537e979f3a490dec3d4ecb2223791383e from: Stefan Sperling via: Thomas Adam date: Tue Sep 21 20:55:42 2021 UTC xmalloc: remove wrapper as no longer needed There is only one user which calls xrecallocarray: ibuf_realloc(). We already provide recallocarray() in the compat layer so ibuf_realloc() can simply call recallocarray() directly, as it does on OpenBSD. OK thomas.adam commit - f0678b77c63a9dc8aa32c781cc38bab77932669d commit + c0faa64537e979f3a490dec3d4ecb2223791383e blob - a50e010273d86503455feace8d8a6c20b9deee7c blob + e17755bcd478b513376c5681575541b0fbf11f6b --- compat/Makefile.am +++ compat/Makefile.am @@ -29,12 +29,10 @@ libopenbsd_compat_a_SOURCES = \ strnlen.c \ strsep.c \ strtonum.c \ - uuid.c \ - xmalloc.c + uuid.c EXTRA_DIST = \ $(top_srcdir)/include/got_compat.h \ imsg.h \ queue.h \ - tree.h \ - xmalloc.h + tree.h blob - 37a41157a351f7ae2bd273a91c7e879e2391bccc blob + ce3ca9baf57a8856dcbf04e41c7a3ff1e07dda10 --- compat/imsg-buffer.c +++ compat/imsg-buffer.c @@ -27,7 +27,6 @@ #include #include "got_compat.h" -#include "xmalloc.h" static int ibuf_realloc(struct ibuf *, size_t); static void ibuf_enqueue(struct msgbuf *, struct ibuf *); @@ -78,7 +77,7 @@ ibuf_realloc(struct ibuf *buf, size_t len) return (-1); } - b = xrecallocarray(buf->buf, buf->size, buf->wpos + len, 1); + b = recallocarray(buf->buf, buf->size, buf->wpos + len, 1); if (b == NULL) return (-1); buf->buf = b; blob - 4cb3fee954c0994f90c6ad916cce9abc291f8614 (mode 644) blob + /dev/null --- compat/xmalloc.c +++ /dev/null @@ -1,185 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Author: Tatu Ylonen - * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland - * All rights reserved - * Versions of malloc and friends that check their results, and never return - * failure (they call fatalx if they encounter an error). - * - * As far as I am concerned, the code I have written for this software - * can be used freely for any purpose. Any derived versions of this - * software must be clearly marked as such, and if the derived work is - * incompatible with the protocol description in the RFC file, it must be - * called by a name other than "ssh" or "Secure Shell". - */ - -#include -#include -#include -#include -#include -#include - -#include "got_compat.h" - -#include "xmalloc.h" - -void * -xmalloc(size_t size) -{ - void *ptr; - - if (size == 0) { - fprintf(stderr,"xmalloc: zero size"); - exit (1); - } - ptr = malloc(size); - if (ptr == NULL) { - fprintf(stderr, "xmalloc: allocating %zu bytes: %s", - size, strerror(errno)); - exit (1); - } - return ptr; -} - -void * -xcalloc(size_t nmemb, size_t size) -{ - void *ptr; - - if (size == 0 || nmemb == 0) - fprintf(stderr,"xcalloc: zero size"); - ptr = calloc(nmemb, size); - if (ptr == NULL) { - fprintf(stderr, "xcalloc: allocating %zu * %zu bytes: %s", - nmemb, size, strerror(errno)); - exit (1); - } - return ptr; -} - -void * -xrealloc(void *ptr, size_t size) -{ - return xreallocarray(ptr, 1, size); -} - -void * -xreallocarray(void *ptr, size_t nmemb, size_t size) -{ - void *new_ptr; - - if (nmemb == 0 || size == 0) { - fprintf(stderr, "xreallocarray: zero size"); - exit (1); - } - new_ptr = reallocarray(ptr, nmemb, size); - if (new_ptr == NULL) { - fprintf(stderr, "xreallocarray: allocating %zu * %zu bytes: %s", - nmemb, size, strerror(errno)); - exit (1); - } - return new_ptr; -} - -void * -xrecallocarray(void *ptr, size_t oldnmemb, size_t nmemb, size_t size) -{ - void *new_ptr; - - if (nmemb == 0 || size == 0) { - fprintf(stderr,"xrecallocarray: zero size"); - exit (1); - } - new_ptr = recallocarray(ptr, oldnmemb, nmemb, size); - if (new_ptr == NULL) { - fprintf(stderr,"xrecallocarray: allocating %zu * %zu bytes: %s", - nmemb, size, strerror(errno)); - exit (1); - } - return new_ptr; -} - -char * -xstrdup(const char *str) -{ - char *cp; - - if ((cp = strdup(str)) == NULL) { - fprintf(stderr,"xstrdup: %s", strerror(errno)); - exit (1); - } - return cp; -} - -char * -xstrndup(const char *str, size_t maxlen) -{ - char *cp; - - if ((cp = strndup(str, maxlen)) == NULL) { - fprintf(stderr,"xstrndup: %s", strerror(errno)); - exit (1); - } - return cp; -} - -int -xasprintf(char **ret, const char *fmt, ...) -{ - va_list ap; - int i; - - va_start(ap, fmt); - i = xvasprintf(ret, fmt, ap); - va_end(ap); - - return i; -} - -int -xvasprintf(char **ret, const char *fmt, va_list ap) -{ - int i; - - i = vasprintf(ret, fmt, ap); - - if (i == -1) { - fprintf(stderr,"xasprintf: %s", strerror(errno)); - exit (1); - } - - return i; -} - -int -xsnprintf(char *str, size_t len, const char *fmt, ...) -{ - va_list ap; - int i; - - va_start(ap, fmt); - i = xvsnprintf(str, len, fmt, ap); - va_end(ap); - - return i; -} - -int -xvsnprintf(char *str, size_t len, const char *fmt, va_list ap) -{ - int i; - - if (len > INT_MAX) - fprintf(stderr,"xsnprintf: len > INT_MAX"); - - i = vsnprintf(str, len, fmt, ap); - - if (i < 0 || i >= (int)len) { - fprintf(stderr,"xsnprintf: overflow"); - exit (1); - } - - return i; -} blob - 82a5624e6cff0daddb85ad48d75031abf9d728f0 (mode 644) blob + /dev/null --- compat/xmalloc.h +++ /dev/null @@ -1,48 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Author: Tatu Ylonen - * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland - * All rights reserved - * Created: Mon Mar 20 22:09:17 1995 ylo - * - * Versions of malloc and friends that check their results, and never return - * failure (they call fatal if they encounter an error). - * - * As far as I am concerned, the code I have written for this software - * can be used freely for any purpose. Any derived versions of this - * software must be clearly marked as such, and if the derived work is - * incompatible with the protocol description in the RFC file, it must be - * called by a name other than "ssh" or "Secure Shell". - */ - -#ifndef XMALLOC_H -#define XMALLOC_H - -#include - -#if !defined(__bounded__) -#define __bounded__(x, y, z) -#endif - -void *xmalloc(size_t); -void *xcalloc(size_t, size_t); -void *xrealloc(void *, size_t); -void *xreallocarray(void *, size_t, size_t); -void *xrecallocarray(void *, size_t, size_t, size_t); -char *xstrdup(const char *); -char *xstrndup(const char *, size_t); -int xasprintf(char **, const char *, ...) - __attribute__((__format__ (printf, 2, 3))) - __attribute__((__nonnull__ (2))); -int xvasprintf(char **, const char *, va_list) - __attribute__((__nonnull__ (2))); -int xsnprintf(char *, size_t, const char *, ...) - __attribute__((__format__ (printf, 3, 4))) - __attribute__((__nonnull__ (3))) - __attribute__((__bounded__ (__string__, 1, 2))); -int xvsnprintf(char *, size_t, const char *, va_list) - __attribute__((__nonnull__ (3))) - __attribute__((__bounded__ (__string__, 1, 2))); - -#endif /* XMALLOC_H */