diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-08-31 23:05:35 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-08-31 23:05:49 +0200 |
commit | 1f895a6ac8aa52d5a5d1b07257b27b62bfca86bb (patch) | |
tree | eddabc6695af999cb6bc48d259a773a53db0867f | |
parent | add _LIBRARY_HEADER (diff) | |
download | slibc-1f895a6ac8aa52d5a5d1b07257b27b62bfca86bb.tar.gz slibc-1f895a6ac8aa52d5a5d1b07257b27b62bfca86bb.tar.bz2 slibc-1f895a6ac8aa52d5a5d1b07257b27b62bfca86bb.tar.xz |
fix strdup functions
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | include/string.h | 15 | ||||
-rw-r--r-- | src/string/strdup.c | 6 |
2 files changed, 10 insertions, 11 deletions
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 <bits/types.h> @@ -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 diff --git a/src/string/strdup.c b/src/string/strdup.c index 27783b9..c65970e 100644 --- a/src/string/strdup.c +++ b/src/string/strdup.c @@ -33,7 +33,7 @@ char* strdup(const char* string) { size_t n = strlen(string) + 1; char* r = malloc(n * sizeof(char)); - return r == NULL ? NULL : memcpy(r, string, n); + return r == NULL ? NULL : memcpy(r, string, n * sizeof(char)); } @@ -55,7 +55,7 @@ char* strndup(const char* string, size_t maxlen) { size_t n = strnlen(string, maxlen) + 1; char* r = malloc(n * sizeof(char)); - return r == NULL ? NULL : memcpy(r, string, n); + return r == NULL ? NULL : memcpy(r, string, n * sizeof(char)); } @@ -73,7 +73,7 @@ char* strndup(const char* string, size_t maxlen) */ void* memdup(const void* segment, size_t size) { - wchar_t* r = malloc(size * sizeof(wchar_t)); + void* r = malloc(size); return r == NULL ? NULL : memcpy(r, segment, size); } |