aboutsummaryrefslogtreecommitdiff
path: root/libbb/xfuncs_printf.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-07-09 13:10:58 +0100
committerRon Yorston <rmy@pobox.com>2020-07-09 13:10:58 +0100
commit9c0b2f7020d7c30b21a930ef54be632e092e533b (patch)
treeb2187c40bd2fd9f49f73599fb08e52cb7a596de0 /libbb/xfuncs_printf.c
parenta8c6e20e332a9e11a9d28cd6770eadb9c9d73cb7 (diff)
parentd21a63f9fca8eb16f79de9b72d4a3484dfaec1fc (diff)
downloadbusybox-w32-9c0b2f7020d7c30b21a930ef54be632e092e533b.tar.gz
busybox-w32-9c0b2f7020d7c30b21a930ef54be632e092e533b.tar.bz2
busybox-w32-9c0b2f7020d7c30b21a930ef54be632e092e533b.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb/xfuncs_printf.c')
-rw-r--r--libbb/xfuncs_printf.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index cfe062a47..6fdc0f6a4 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -93,26 +93,17 @@ char* FAST_FUNC xstrdup(const char *s)
93// the (possibly truncated to length n) string into it. 93// the (possibly truncated to length n) string into it.
94char* FAST_FUNC xstrndup(const char *s, int n) 94char* FAST_FUNC xstrndup(const char *s, int n)
95{ 95{
96 int m;
97 char *t; 96 char *t;
98 97
99 if (ENABLE_DEBUG && s == NULL) 98 if (ENABLE_DEBUG && s == NULL)
100 bb_simple_error_msg_and_die("xstrndup bug"); 99 bb_simple_error_msg_and_die("xstrndup bug");
101 100
102 /* We can just xmalloc(n+1) and strncpy into it, */ 101 t = strndup(s, n);
103 /* but think about xstrndup("abc", 10000) wastage! */
104 m = n;
105 t = (char*) s;
106 while (m) {
107 if (!*t) break;
108 m--;
109 t++;
110 }
111 n -= m;
112 t = xmalloc(n + 1);
113 t[n] = '\0';
114 102
115 return memcpy(t, s, n); 103 if (t == NULL)
104 bb_die_memory_exhausted();
105
106 return t;
116} 107}
117 108
118void* FAST_FUNC xmemdup(const void *s, int n) 109void* FAST_FUNC xmemdup(const void *s, int n)