diff options
Diffstat (limited to 'include/wchar.h')
| -rw-r--r-- | include/wchar.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/include/wchar.h b/include/wchar.h index b3a1dc7..69c2188 100644 --- a/include/wchar.h +++ b/include/wchar.h | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #ifndef FORTIFY_WCHAR_H_ | 1 | #ifndef FORTIFY_WCHAR_H_ |
| 2 | #define FORTIFY_WCHAR_H_ | 2 | #define FORTIFY_WCHAR_H_ |
| 3 | 3 | ||
| 4 | #include_next <stdlib.h> | ||
| 4 | #include_next <wchar.h> | 5 | #include_next <wchar.h> |
| 5 | 6 | ||
| 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | 7 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 |
| @@ -52,6 +53,39 @@ __fortify_mbstowcs(wchar_t *d, const char *s, size_t n) | |||
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | static inline __attribute__ ((always_inline)) | 55 | static inline __attribute__ ((always_inline)) |
| 56 | size_t | ||
| 57 | __fortify_wcrtomb(char *s, wchar_t wc, mbstate_t *st) | ||
| 58 | { | ||
| 59 | size_t bos = __builtin_object_size(s, 0); | ||
| 60 | |||
| 61 | if (MB_CUR_MAX > bos) | ||
| 62 | __builtin_trap(); | ||
| 63 | return wcrtomb(s, wc, st); | ||
| 64 | } | ||
| 65 | |||
| 66 | static inline __attribute__ ((always_inline)) | ||
| 67 | wchar_t * | ||
| 68 | __fortify_wcscat(wchar_t *d, const wchar_t *s) | ||
| 69 | { | ||
| 70 | size_t bos = __builtin_object_size(d, 0); | ||
| 71 | |||
| 72 | if (wcslen(s) + wcslen(d) + 1 > bos / sizeof(wchar_t)) | ||
| 73 | __builtin_trap(); | ||
| 74 | return wcscat(d, s); | ||
| 75 | } | ||
| 76 | |||
| 77 | static inline __attribute__ ((always_inline)) | ||
| 78 | wchar_t * | ||
| 79 | __fortify_wcscpy(wchar_t *d, const wchar_t *s) | ||
| 80 | { | ||
| 81 | size_t bos = __builtin_object_size(d, 0); | ||
| 82 | |||
| 83 | if (wcslen(s) + 1 > bos / sizeof(wchar_t)) | ||
| 84 | __builtin_trap(); | ||
| 85 | return wcscpy(d, s); | ||
| 86 | } | ||
| 87 | |||
| 88 | static inline __attribute__ ((always_inline)) | ||
| 55 | wchar_t * | 89 | wchar_t * |
| 56 | __fortify_wmemcpy(wchar_t *d, const wchar_t *s, size_t n) | 90 | __fortify_wmemcpy(wchar_t *d, const wchar_t *s, size_t n) |
| 57 | { | 91 | { |
| @@ -92,6 +126,12 @@ __fortify_wmemset(wchar_t *s, wchar_t c, size_t n) | |||
| 92 | #define mbsrtowcs(d, s, wn, st) __fortify_mbsrtowcs(d, s, wn, st) | 126 | #define mbsrtowcs(d, s, wn, st) __fortify_mbsrtowcs(d, s, wn, st) |
| 93 | #undef mbstowcs | 127 | #undef mbstowcs |
| 94 | #define mbstowcs(d, s, n) __fortify_mbstowcs(d, s, n) | 128 | #define mbstowcs(d, s, n) __fortify_mbstowcs(d, s, n) |
| 129 | #undef wcrtomb | ||
| 130 | #define wcrtomb(s, wc, st) __fortify_wcrtomb(s, wc, st) | ||
| 131 | #undef wcscat | ||
| 132 | #define wcscat(d, s) __fortify_wcscat(d, s) | ||
| 133 | #undef wcscpy | ||
| 134 | #define wcscpy(d, s) __fortify_wcscpy(d, s) | ||
| 95 | #undef wmemcpy | 135 | #undef wmemcpy |
| 96 | #define wmemcpy(d, s, n) __fortify_wmemcpy(d, s, n) | 136 | #define wmemcpy(d, s, n) __fortify_wmemcpy(d, s, n) |
| 97 | #undef wmemmove | 137 | #undef wmemmove |
