Skip to content

Commit 8ec4b46

Browse files
author
Ishimoto Shinobu
committed
fixes
Signed-off-by: Ishimoto Shinobu <[email protected]>
1 parent 9a0a84c commit 8ec4b46

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

include/bsd.h

+5
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,8 @@ uintmax_t strtou(const char * __restrict, char ** __restrict, int,
169169
int vasprintf(char ** __restrict, const char * __restrict,
170170
__va_list)
171171
__printflike(2, 0);
172+
173+
/* __OpenBSD */
174+
#ifndef __GLIBC__
175+
void *reallocarray(void *, size_t, size_t);
176+
#endif

src/libnetbsd/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ libnetbsd_a_SOURCES = efun.c \
1111
pwcache.c \
1212
setprogname.c \
1313
reallocarr.c \
14+
reallocarray.c \
1415
raise_default_signal.c \
1516
setmode.c \
1617
stat_flags.c \

src/libnetbsd/reallocarray.c

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* $OpenBSD: reallocarray.c,v 1.3 2015/09/13 08:31:47 guenther Exp $ */
2+
/*
3+
* Copyright (c) 2008 Otto Moerbeek <[email protected]>
4+
*
5+
* Permission to use, copy, modify, and distribute this software for any
6+
* purpose with or without fee is hereby granted, provided that the above
7+
* copyright notice and this permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
*/
17+
18+
#include <sys/types.h>
19+
#include <errno.h>
20+
#include <stdint.h>
21+
#include <stdlib.h>
22+
#include <bsd.h>
23+
24+
/*
25+
* This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
26+
* if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
27+
*/
28+
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
29+
30+
void *
31+
reallocarray(void *optr, size_t nmemb, size_t size)
32+
{
33+
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
34+
nmemb > 0 && SIZE_MAX / nmemb < size) {
35+
errno = ENOMEM;
36+
return NULL;
37+
}
38+
return realloc(optr, size * nmemb);
39+
}
40+
DEF_WEAK(reallocarray);

src/pax/Makefile.am

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ pax_LDADD = ../libnetbsd/libnetbsd.a
66
man1_MANS = pax.1 tar.1 cpio.1
77

88
install-exec-hook:
9-
$(LN_S) pax $(bindir)/cpio
10-
$(LN_S) pax $(bindir)/tar
9+
ln -sf pax $(DESTDIR)$(bindir)/cpio
10+
ln -sf pax $(DESTDIR)$(bindir)/tar

0 commit comments

Comments
 (0)