diff options
| author | Joseph Myers <josmyers@redhat.com> | 2025-10-01 15:14:09 +0000 |
|---|---|---|
| committer | Joseph Myers <josmyers@redhat.com> | 2025-10-01 15:14:09 +0000 |
| commit | 0f201f4a817e39c01c502f523d4ea3c91f242767 (patch) | |
| tree | 363f693dbff6fd086faf1bfd89e014346837436e /string/bits | |
| parent | a8ad2e9e431bac3ea207be07c64cddb72c290cde (diff) | |
Implement C23 memset_explicit (bug 32378)
Add the C23 memset_explicit function to glibc. Everything here is
closely based on the approach taken for explicit_bzero. This includes
the bits that relate to internal uses of explicit_bzero within glibc
(although we don't currently have any such internal uses of
memset_explicit), and also includes the nonnull attribute (when we
move to nonnull_if_nonzero for various functions following C2y, this
function should be included in that change).
The function is declared both for __USE_MISC and for __GLIBC_USE (ISOC23)
(so by default not just for compilers defaulting to C23 mode).
Tested for x86_64 and x86.
Diffstat (limited to 'string/bits')
| -rw-r--r-- | string/bits/string_fortified.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/string/bits/string_fortified.h b/string/bits/string_fortified.h index ae14cfbab0..9916e17aa0 100644 --- a/string/bits/string_fortified.h +++ b/string/bits/string_fortified.h @@ -60,6 +60,18 @@ __NTH (memset (void *__dest, int __ch, size_t __len)) __glibc_objsize0 (__dest)); } +#if defined __USE_MISC || __GLIBC_USE (ISOC23) +void *__memset_explicit_chk (void *__s, int __c, size_t __n, size_t __destlen) + __THROW __nonnull ((1)) __fortified_attr_access (__write_only__, 1, 3); + +__fortify_function void * +__NTH (memset_explicit (void *__dest, int __ch, size_t __len)) +{ + return __memset_explicit_chk (__dest, __ch, __len, + __glibc_objsize0 (__dest)); +} +#endif + #ifdef __USE_MISC # include <bits/strings_fortified.h> |
