aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-08-31 20:00:31 +0200
committerMattias Andrée <maandree@operamail.com>2015-08-31 20:00:31 +0200
commit70f4df4cd8b51f7406914a38d268d0d431e8f55a (patch)
treec17dc9cacf5cf38b61a8b154245894651a7c3386
parentadd bcopy (diff)
downloadslibc-70f4df4cd8b51f7406914a38d268d0d431e8f55a.tar.gz
slibc-70f4df4cd8b51f7406914a38d268d0d431e8f55a.tar.bz2
slibc-70f4df4cd8b51f7406914a38d268d0d431e8f55a.tar.xz
fix dupa macros
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--include/string.h19
-rw-r--r--include/wchar.h27
2 files changed, 26 insertions, 20 deletions
diff --git a/include/string.h b/include/string.h
index 6c5c80e..09bdc5e 100644
--- a/include/string.h
+++ b/include/string.h
@@ -655,9 +655,10 @@ void* memdup(const void*, size_t)
*/
# define strdupa(string) \
({ \
- size_t n = strlen(string) + 1; \
- char* r = __builtin_alloca(n * sizeof(char)); \
- memcpy(r, string, n); \
+ const char* __s = (string); \
+ size_t __n = strlen(__s) + 1; \
+ char* __r = __builtin_alloca(__n * sizeof(char)); \
+ memcpy(__r, __s, __n); \
})
# endif
@@ -676,9 +677,10 @@ void* memdup(const void*, size_t)
*/
# define strndupa(string, maxlen) \
({ \
- size_t n = strnlen(string, maxlen) + 1; \
- char* r = __builtin_alloca(n * sizeof(char)); \
- memcpy(r, string, n); \
+ const char* __s = (string); \
+ size_t __n = strnlen(__s, (maxlen)) + 1; \
+ char* __r = __builtin_alloca(__n * sizeof(char)); \
+ memcpy(__r, __s, __n); \
})
# endif
@@ -696,8 +698,9 @@ void* memdup(const void*, size_t)
*/
# define memdupa(segment, size) \
({ \
- wchar_t* r = __builtin_alloca(size * sizeof(wchar_t)); \
- memcpy(r, segment, size); \
+ size_t __n = (size); \
+ wchar_t* __r = __builtin_alloca(__n * sizeof(wchar_t)); \
+ memcpy(__r, (segment), __n); \
})
# endif
# endif
diff --git a/include/wchar.h b/include/wchar.h
index 32f32b0..d00056e 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -580,11 +580,12 @@ wchar_t* wmemdup(const wchar_t*, size_t)
* @return :size_t The new string. There is no way to
* detect whether the allocation failed.
*/
-# define wcsdupa(string) \
- ({ \
- size_t n = wcslen(string) + 1; \
- wchar_t* r = __builtin_alloca(n * sizeof(char)); \
- wmemcpy(r, string, n); \
+# define wcsdupa(string) \
+ ({ \
+ const char* __s = (string); \
+ size_t __n = wcslen(__s) + 1; \
+ wchar_t* __r = __builtin_alloca(__n * sizeof(char)); \
+ wmemcpy(__r, __s, __n); \
})
/**
@@ -600,11 +601,12 @@ wchar_t* wmemdup(const wchar_t*, size_t)
* @return :size_t The new string. There is no way to
* detect whether the allocation failed.
*/
-# define wstrndupa(string, maxlen) \
- ({ \
- size_t n = wcsnlen(string, maxlen) + 1; \
- wchar_t* r = __builtin_alloca(n * sizeof(wchar_t)); \
- wmemcpy(r, string, n); \
+# define wstrndupa(string, maxlen) \
+ ({ \
+ const char* __s = (string); \
+ size_t __n = wcsnlen(__s, (maxlen)) + 1; \
+ wchar_t* __r = __builtin_alloca(__n * sizeof(wchar_t)); \
+ wmemcpy(__r, __s, __n); \
})
# endif
@@ -621,8 +623,9 @@ wchar_t* wmemdup(const wchar_t*, size_t)
*/
# define wmemdupa(segment, size) \
({ \
- wchar_t* r = __builtin_alloca(size * sizeof(wchar_t)); \
- wmemcpy(r, segmetn, size); \
+ size_t __n = (size); \
+ wchar_t* __r = __builtin_alloca(__n * sizeof(wchar_t)); \
+ wmemcpy(__r, (segmetn), __n); \
})
# endif
# endif