diff options
| author | sin | 2015-07-15 15:53:41 +0100 |
|---|---|---|
| committer | sin | 2015-07-15 15:55:56 +0100 |
| commit | a255506ca487250255f9f048e61cf90166ceab77 (patch) | |
| tree | 39860ac90483b57926b94da597988de2277a0a66 /include | |
| parent | 7fd984fcb532be01f68cddc194c09a7ca10c1ea6 (diff) | |
Fix wcrtomb() check
This was breaking valid code, example:
char c;
wcrtomb(&c, L'0', st);
Diffstat (limited to 'include')
| -rw-r--r-- | include/wchar.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/include/wchar.h b/include/wchar.h index 0d4abfa..d87e195 100644 --- a/include/wchar.h +++ b/include/wchar.h | |||
| @@ -17,8 +17,12 @@ | |||
| 17 | #define _FORTIFY_WCHAR_H | 17 | #define _FORTIFY_WCHAR_H |
| 18 | 18 | ||
| 19 | __extension__ | 19 | __extension__ |
| 20 | #include_next <limits.h> | ||
| 21 | __extension__ | ||
| 20 | #include_next <stdlib.h> | 22 | #include_next <stdlib.h> |
| 21 | __extension__ | 23 | __extension__ |
| 24 | #include_next <string.h> | ||
| 25 | __extension__ | ||
| 22 | #include_next <wchar.h> | 26 | #include_next <wchar.h> |
| 23 | 27 | ||
| 24 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | 28 | #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 | |||
| 99 | 103 | ||
| 100 | _FORTIFY_FN(wcrtomb) size_t wcrtomb(char *__s, wchar_t __w, mbstate_t *__st) | 104 | _FORTIFY_FN(wcrtomb) size_t wcrtomb(char *__s, wchar_t __w, mbstate_t *__st) |
| 101 | { | 105 | { |
| 106 | char __buf[MB_LEN_MAX]; | ||
| 102 | size_t __b = __builtin_object_size(__s, 0); | 107 | size_t __b = __builtin_object_size(__s, 0); |
| 108 | size_t __r; | ||
| 103 | 109 | ||
| 104 | if (__s && MB_CUR_MAX > __b) | 110 | if (__s) { |
| 105 | __builtin_trap(); | 111 | __r = __orig_wcrtomb(__buf, __w, __st); |
| 112 | if (__r > __b) | ||
| 113 | __builtin_trap(); | ||
| 114 | memcpy(__s, __buf, __r); | ||
| 115 | return __r; | ||
| 116 | } | ||
| 106 | return __orig_wcrtomb(__s, __w, __st); | 117 | return __orig_wcrtomb(__s, __w, __st); |
| 107 | } | 118 | } |
| 108 | 119 | ||
