[git commit] libbb: change xstrndup, xmemdup to take size_t as size parameter

Denys Vlasenko vda.linux at googlemail.com
Wed Jan 5 22:03:54 UTC 2022


commit: https://git.busybox.net/busybox/commit/?id=6062c0d19bc201cbeb61b8875598cdd7a14a5ae0
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

Also, remove entirely usually-disabled paranoia check (was also using
wrong config option to enable itself).

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 include/libbb.h       | 4 ++--
 libbb/xfuncs_printf.c | 7 ++-----
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/include/libbb.h b/include/libbb.h
index c93058f6d..daa310776 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -429,8 +429,8 @@ void *xrealloc(void *old, size_t size) FAST_FUNC;
 	xrealloc_vector_helper((vector), (sizeof((vector)[0]) << 8) + (shift), (idx))
 void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) FAST_FUNC;
 char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC;
-char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
-void *xmemdup(const void *s, int n) FAST_FUNC RETURNS_MALLOC;
+char *xstrndup(const char *s, size_t n) FAST_FUNC RETURNS_MALLOC;
+void *xmemdup(const void *s, size_t n) FAST_FUNC RETURNS_MALLOC;
 void *mmap_read(int fd, size_t size) FAST_FUNC;
 void *mmap_anon(size_t size) FAST_FUNC;
 void *xmmap_anon(size_t size) FAST_FUNC;
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index d29acebcd..fc630d176 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -91,13 +91,10 @@ char* FAST_FUNC xstrdup(const char *s)
 
 // Die if we can't allocate n+1 bytes (space for the null terminator) and copy
 // the (possibly truncated to length n) string into it.
-char* FAST_FUNC xstrndup(const char *s, int n)
+char* FAST_FUNC xstrndup(const char *s, size_t n)
 {
 	char *t;
 
-	if (ENABLE_DEBUG && s == NULL)
-		bb_simple_error_msg_and_die("xstrndup bug");
-
 	t = strndup(s, n);
 
 	if (t == NULL)
@@ -106,7 +103,7 @@ char* FAST_FUNC xstrndup(const char *s, int n)
 	return t;
 }
 
-void* FAST_FUNC xmemdup(const void *s, int n)
+void* FAST_FUNC xmemdup(const void *s, size_t n)
 {
 	return memcpy(xmalloc(n), s, n);
 }


More information about the busybox-cvs mailing list