From a255506ca487250255f9f048e61cf90166ceab77 Mon Sep 17 00:00:00 2001 From: sin Date: Wed, 15 Jul 2015 15:53:41 +0100 Subject: Fix wcrtomb() check This was breaking valid code, example: char c; wcrtomb(&c, L'0', st); --- include/wchar.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/wchar.h b/include/wchar.h index 0d4abfa..d87e195 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -16,9 +16,13 @@ #ifndef _FORTIFY_WCHAR_H #define _FORTIFY_WCHAR_H +__extension__ +#include_next __extension__ #include_next __extension__ +#include_next +__extension__ #include_next #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 @@ -99,10 +103,17 @@ _FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t *__ws, const char *__s, size_t __w _FORTIFY_FN(wcrtomb) size_t wcrtomb(char *__s, wchar_t __w, mbstate_t *__st) { + char __buf[MB_LEN_MAX]; size_t __b = __builtin_object_size(__s, 0); + size_t __r; - if (__s && MB_CUR_MAX > __b) - __builtin_trap(); + if (__s) { + __r = __orig_wcrtomb(__buf, __w, __st); + if (__r > __b) + __builtin_trap(); + memcpy(__s, __buf, __r); + return __r; + } return __orig_wcrtomb(__s, __w, __st); } -- cgit v1.3