From 1f895a6ac8aa52d5a5d1b07257b27b62bfca86bb Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 31 Aug 2015 23:05:35 +0200 Subject: fix strdup functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- include/string.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/string.h b/include/string.h index 5891dbb..0a41899 100644 --- a/include/string.h +++ b/include/string.h @@ -23,7 +23,6 @@ #define __NEED_size_t -#define __NEED_wchar_t #define __NEED_locale_t /* TODO not defined */ #include @@ -656,7 +655,7 @@ void* memdup(const void*, size_t) const char* __s = (string); \ size_t __n = strlen(__s) + 1; \ char* __r = __builtin_alloca(__n * sizeof(char)); \ - memcpy(__r, __s, __n); \ + memcpy(__r, __s, __n * sizeof(char)); \ }) # endif @@ -678,7 +677,7 @@ void* memdup(const void*, size_t) const char* __s = (string); \ size_t __n = strnlen(__s, (maxlen)) + 1; \ char* __r = __builtin_alloca(__n * sizeof(char)); \ - memcpy(__r, __s, __n); \ + memcpy(__r, __s, __n * sizeof(char)); \ }) # endif @@ -694,11 +693,11 @@ void* memdup(const void*, size_t) * @return :size_t The new segment. There is no way to * detect whether the allocation failed. */ -# define memdupa(segment, size) \ - ({ \ - size_t __n = (size); \ - wchar_t* __r = __builtin_alloca(__n * sizeof(wchar_t)); \ - memcpy(__r, (segment), __n); \ +# define memdupa(segment, size) \ + ({ \ + size_t __n = (size); \ + void* __r = __builtin_alloca(__n); \ + memcpy(__r, (segment), __n); \ }) # endif # endif -- cgit v1.2.3-70-g09d2