diff options
| author | Daniel Kolesa | 2022-10-26 00:30:00 +0200 |
|---|---|---|
| committer | jvoisin | 2023-06-25 18:26:45 +0200 |
| commit | fe149628eaae9748be08815d726cc56e8e492c73 (patch) | |
| tree | 252ed41ea13504b67b3c03e648113015b8f85dda /include/string.h | |
| parent | adae76af26e498af6c3004a52a4b1de2c6fd91c3 (diff) | |
add initial clang support
Diffstat (limited to 'include/string.h')
| -rw-r--r-- | include/string.h | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/include/string.h b/include/string.h index c9f8839..bbf24fe 100644 --- a/include/string.h +++ b/include/string.h | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> | 2 | * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> |
| 3 | * Copyright (C) 2022 q66 <q66@chimera-linux.org> | ||
| 3 | * | 4 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any | 5 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted. | 6 | * purpose with or without fee is hereby granted. |
| @@ -38,7 +39,8 @@ extern "C" { | |||
| 38 | 39 | ||
| 39 | __access(write_only, 1) | 40 | __access(write_only, 1) |
| 40 | __access(read_only, 2, 3) | 41 | __access(read_only, 2, 3) |
| 41 | _FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n) | 42 | _FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od, |
| 43 | const void * _FORTIFY_POS0 __os, size_t __n) | ||
| 42 | { | 44 | { |
| 43 | size_t __bd = __bos(__od, 0); | 45 | size_t __bd = __bos(__od, 0); |
| 44 | size_t __bs = __bos(__os, 0); | 46 | size_t __bs = __bos(__os, 0); |
| @@ -57,7 +59,8 @@ _FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n) | |||
| 57 | 59 | ||
| 58 | __access(write_only, 1) | 60 | __access(write_only, 1) |
| 59 | __access(read_only, 2, 3) | 61 | __access(read_only, 2, 3) |
| 60 | _FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n) | 62 | _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d, |
| 63 | const void * _FORTIFY_POS0 __s, size_t __n) | ||
| 61 | { | 64 | { |
| 62 | size_t __bd = __bos(__d, 0); | 65 | size_t __bd = __bos(__d, 0); |
| 63 | size_t __bs = __bos(__s, 0); | 66 | size_t __bs = __bos(__s, 0); |
| @@ -68,7 +71,7 @@ _FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n) | |||
| 68 | } | 71 | } |
| 69 | 72 | ||
| 70 | __access(write_only, 1) | 73 | __access(write_only, 1) |
| 71 | _FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n) | 74 | _FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n) |
| 72 | { | 75 | { |
| 73 | size_t __b = __bos(__d, 0); | 76 | size_t __b = __bos(__d, 0); |
| 74 | 77 | ||
| @@ -83,7 +86,7 @@ _FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n) | |||
| 83 | #undef stpcpy | 86 | #undef stpcpy |
| 84 | __access(write_only, 1) | 87 | __access(write_only, 1) |
| 85 | __access(read_only, 2) | 88 | __access(read_only, 2) |
| 86 | _FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s) | 89 | _FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s) |
| 87 | { | 90 | { |
| 88 | size_t __n = strlen(__s) + 1; | 91 | size_t __n = strlen(__s) + 1; |
| 89 | 92 | ||
| @@ -102,7 +105,8 @@ _FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s) | |||
| 102 | #undef stpncpy | 105 | #undef stpncpy |
| 103 | __access(write_only, 1) | 106 | __access(write_only, 1) |
| 104 | __access(read_only, 2, 3) | 107 | __access(read_only, 2, 3) |
| 105 | _FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n) | 108 | _FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s, |
| 109 | size_t __n) | ||
| 106 | { | 110 | { |
| 107 | /* trap if pointers are overlapping but not if dst == src. | 111 | /* trap if pointers are overlapping but not if dst == src. |
| 108 | * gcc seems to like to generate code that relies on dst == src */ | 112 | * gcc seems to like to generate code that relies on dst == src */ |
| @@ -119,7 +123,7 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n) | |||
| 119 | 123 | ||
| 120 | __access (read_write, 1) | 124 | __access (read_write, 1) |
| 121 | __access (read_only, 2) | 125 | __access (read_only, 2) |
| 122 | _FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s) | 126 | _FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s) |
| 123 | { | 127 | { |
| 124 | size_t __b = __bos(__d, 0); | 128 | size_t __b = __bos(__d, 0); |
| 125 | 129 | ||
| @@ -130,7 +134,7 @@ _FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s) | |||
| 130 | 134 | ||
| 131 | __access (write_only, 1) | 135 | __access (write_only, 1) |
| 132 | __access (read_only, 2) | 136 | __access (read_only, 2) |
| 133 | _FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s) | 137 | _FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s) |
| 134 | { | 138 | { |
| 135 | size_t __n = strlen(__s) + 1; | 139 | size_t __n = strlen(__s) + 1; |
| 136 | 140 | ||
| @@ -148,7 +152,8 @@ _FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s) | |||
| 148 | 152 | ||
| 149 | __access (read_write, 1) | 153 | __access (read_write, 1) |
| 150 | __access (read_only, 2, 3) | 154 | __access (read_only, 2, 3) |
| 151 | _FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n) | 155 | _FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s, |
| 156 | size_t __n) | ||
| 152 | { | 157 | { |
| 153 | size_t __b = __bos(__d, 0); | 158 | size_t __b = __bos(__d, 0); |
| 154 | 159 | ||
| @@ -165,7 +170,8 @@ _FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n) | |||
| 165 | 170 | ||
| 166 | __access (write_only, 1) | 171 | __access (write_only, 1) |
| 167 | __access (read_only, 2, 3) | 172 | __access (read_only, 2, 3) |
| 168 | _FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n) | 173 | _FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d, |
| 174 | const char *__s, size_t __n) | ||
| 169 | { | 175 | { |
| 170 | /* trap if pointers are overlapping but not if dst == src. | 176 | /* trap if pointers are overlapping but not if dst == src. |
| 171 | * gcc seems to like to generate code that relies on dst == src */ | 177 | * gcc seems to like to generate code that relies on dst == src */ |
| @@ -183,7 +189,8 @@ _FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n) | |||
| 183 | #undef mempcpy | 189 | #undef mempcpy |
| 184 | __access(write_only, 1) | 190 | __access(write_only, 1) |
| 185 | __access(read_only, 2, 3) | 191 | __access(read_only, 2, 3) |
| 186 | _FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n) | 192 | _FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d, |
| 193 | const void * _FORTIFY_POS0 __s, size_t __n) | ||
| 187 | { | 194 | { |
| 188 | size_t __bd = __bos(__d, 0); | 195 | size_t __bd = __bos(__d, 0); |
| 189 | size_t __bs = __bos(__s, 0); | 196 | size_t __bs = __bos(__s, 0); |
| @@ -199,7 +206,8 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n) | |||
| 199 | #undef strlcpy | 206 | #undef strlcpy |
| 200 | __access (read_write, 1) | 207 | __access (read_write, 1) |
| 201 | __access (read_only, 2, 3) | 208 | __access (read_only, 2, 3) |
| 202 | _FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n) | 209 | _FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d, |
| 210 | const char *__s, size_t __n) | ||
| 203 | { | 211 | { |
| 204 | size_t __b = __bos(__d, 0); | 212 | size_t __b = __bos(__d, 0); |
| 205 | 213 | ||
| @@ -210,7 +218,8 @@ _FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n) | |||
| 210 | 218 | ||
| 211 | __access (write_only, 1) | 219 | __access (write_only, 1) |
| 212 | __access (read_only, 2, 3) | 220 | __access (read_only, 2, 3) |
| 213 | _FORTIFY_FN(strlcpy) size_t strlcpy(char *__d, const char *__s, size_t __n) | 221 | _FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d, |
| 222 | const char *__s, size_t __n) | ||
| 214 | { | 223 | { |
| 215 | size_t __b = __bos(__d, 0); | 224 | size_t __b = __bos(__d, 0); |
| 216 | 225 | ||
