diff options
| author | jvoisin | 2023-03-18 14:01:02 +0100 |
|---|---|---|
| committer | jvoisin | 2025-10-31 22:16:21 +0100 |
| commit | 249492e08adbf034976770ab3b021ba093a2ab18 (patch) | |
| tree | cd04ae414fa7ef646a31f767b9295946fd2c9987 /include/string.h | |
| parent | e3fee64643279c144efd3d6856ed4e818c0d5ca2 (diff) | |
Make use of __builtin_dynamic_object_size
GCC and Clang provide __builtin_dynamic_object_size
(see documentation: https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html),
so we should make use of it when its available.
Diffstat (limited to 'include/string.h')
| -rw-r--r-- | include/string.h | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/include/string.h b/include/string.h index 66c23e1..f08eb4c 100644 --- a/include/string.h +++ b/include/string.h | |||
| @@ -38,8 +38,8 @@ extern "C" { | |||
| 38 | 38 | ||
| 39 | _FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n) | 39 | _FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n) |
| 40 | { | 40 | { |
| 41 | size_t __bd = __builtin_object_size(__od, 0); | 41 | size_t __bd = __bos(__od, 0); |
| 42 | size_t __bs = __builtin_object_size(__os, 0); | 42 | size_t __bs = __bos(__os, 0); |
| 43 | char *__d = (char *)__od; | 43 | char *__d = (char *)__od; |
| 44 | const char *__s = (const char *)__os; | 44 | const char *__s = (const char *)__os; |
| 45 | 45 | ||
| @@ -55,8 +55,8 @@ _FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n) | |||
| 55 | 55 | ||
| 56 | _FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n) | 56 | _FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n) |
| 57 | { | 57 | { |
| 58 | size_t __bd = __builtin_object_size(__d, 0); | 58 | size_t __bd = __bos(__d, 0); |
| 59 | size_t __bs = __builtin_object_size(__s, 0); | 59 | size_t __bs = __bos(__s, 0); |
| 60 | 60 | ||
| 61 | if (__n > __bd || __n > __bs) | 61 | if (__n > __bd || __n > __bs) |
| 62 | __builtin_trap(); | 62 | __builtin_trap(); |
| @@ -65,7 +65,7 @@ _FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n) | |||
| 65 | 65 | ||
| 66 | _FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n) | 66 | _FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n) |
| 67 | { | 67 | { |
| 68 | size_t __b = __builtin_object_size(__d, 0); | 68 | size_t __b = __bos(__d, 0); |
| 69 | 69 | ||
| 70 | if (__n > __b) | 70 | if (__n > __b) |
| 71 | __builtin_trap(); | 71 | __builtin_trap(); |
| @@ -78,7 +78,7 @@ _FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n) | |||
| 78 | #undef stpcpy | 78 | #undef stpcpy |
| 79 | _FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s) | 79 | _FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s) |
| 80 | { | 80 | { |
| 81 | size_t __b = __builtin_object_size(__d, 0); | 81 | size_t __b = __bos(__d, 0); |
| 82 | 82 | ||
| 83 | if (strlen(__s) + 1 > __b) | 83 | if (strlen(__s) + 1 > __b) |
| 84 | __builtin_trap(); | 84 | __builtin_trap(); |
| @@ -88,7 +88,7 @@ _FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s) | |||
| 88 | #undef stpncpy | 88 | #undef stpncpy |
| 89 | _FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n) | 89 | _FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n) |
| 90 | { | 90 | { |
| 91 | size_t __b = __builtin_object_size(__d, 0); | 91 | size_t __b = __bos(__d, 0); |
| 92 | 92 | ||
| 93 | if (__n > __b && strlen(__s) + 1 > __b) | 93 | if (__n > __b && strlen(__s) + 1 > __b) |
| 94 | __builtin_trap(); | 94 | __builtin_trap(); |
| @@ -98,7 +98,7 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n) | |||
| 98 | 98 | ||
| 99 | _FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s) | 99 | _FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s) |
| 100 | { | 100 | { |
| 101 | size_t __b = __builtin_object_size(__d, 0); | 101 | size_t __b = __bos(__d, 0); |
| 102 | 102 | ||
| 103 | if (strlen(__s) + strlen(__d) + 1 > __b) | 103 | if (strlen(__s) + strlen(__d) + 1 > __b) |
| 104 | __builtin_trap(); | 104 | __builtin_trap(); |
| @@ -107,7 +107,7 @@ _FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s) | |||
| 107 | 107 | ||
| 108 | _FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s) | 108 | _FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s) |
| 109 | { | 109 | { |
| 110 | size_t __b = __builtin_object_size(__d, 0); | 110 | size_t __b = __bos(__d, 0); |
| 111 | 111 | ||
| 112 | if (strlen(__s) + 1 > __b) | 112 | if (strlen(__s) + 1 > __b) |
| 113 | __builtin_trap(); | 113 | __builtin_trap(); |
| @@ -116,7 +116,7 @@ _FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s) | |||
| 116 | 116 | ||
| 117 | _FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n) | 117 | _FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n) |
| 118 | { | 118 | { |
| 119 | size_t __b = __builtin_object_size(__d, 0); | 119 | size_t __b = __bos(__d, 0); |
| 120 | size_t __sl, __dl; | 120 | size_t __sl, __dl; |
| 121 | 121 | ||
| 122 | if (__n > __b) { | 122 | if (__n > __b) { |
| @@ -132,7 +132,7 @@ _FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n) | |||
| 132 | 132 | ||
| 133 | _FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n) | 133 | _FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n) |
| 134 | { | 134 | { |
| 135 | size_t __b = __builtin_object_size(__d, 0); | 135 | size_t __b = __bos(__d, 0); |
| 136 | 136 | ||
| 137 | if (__n > __b) | 137 | if (__n > __b) |
| 138 | __builtin_trap(); | 138 | __builtin_trap(); |
| @@ -143,8 +143,8 @@ _FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n) | |||
| 143 | #undef mempcpy | 143 | #undef mempcpy |
| 144 | _FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n) | 144 | _FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n) |
| 145 | { | 145 | { |
| 146 | size_t __bd = __builtin_object_size(__d, 0); | 146 | size_t __bd = __bos(__d, 0); |
| 147 | size_t __bs = __builtin_object_size(__s, 0); | 147 | size_t __bs = __bos(__s, 0); |
| 148 | 148 | ||
| 149 | if (__n > __bd || __n > __bs) | 149 | if (__n > __bd || __n > __bs) |
| 150 | __builtin_trap(); | 150 | __builtin_trap(); |
| @@ -157,7 +157,7 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n) | |||
| 157 | #undef strlcpy | 157 | #undef strlcpy |
| 158 | _FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n) | 158 | _FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n) |
| 159 | { | 159 | { |
| 160 | size_t __b = __builtin_object_size(__d, 0); | 160 | size_t __b = __bos(__d, 0); |
| 161 | 161 | ||
| 162 | if (__n > __b) | 162 | if (__n > __b) |
| 163 | __builtin_trap(); | 163 | __builtin_trap(); |
| @@ -166,7 +166,7 @@ _FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n) | |||
| 166 | 166 | ||
| 167 | _FORTIFY_FN(strlcpy) size_t strlcpy(char *__d, const char *__s, size_t __n) | 167 | _FORTIFY_FN(strlcpy) size_t strlcpy(char *__d, const char *__s, size_t __n) |
| 168 | { | 168 | { |
| 169 | size_t __b = __builtin_object_size(__d, 0); | 169 | size_t __b = __bos(__d, 0); |
| 170 | 170 | ||
| 171 | if (__n > __b) | 171 | if (__n > __b) |
| 172 | __builtin_trap(); | 172 | __builtin_trap(); |
