10
10
11
11
#if defined(__APPLE__ ) && defined(__MACH__ )
12
12
#include <AvailabilityMacros.h>
13
+ // memset_s is available from macOS 10.9, iOS 7, watchOS 2, and on all tvOS and visionOS versions.
14
+ # if (defined(MAC_OS_X_VERSION_MIN_REQUIRED ) && (MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_9 ))
15
+ # define APPLE_HAS_MEMSET_S 1
16
+ # elif (defined(__IPHONE_OS_VERSION_MIN_REQUIRED ) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_7_0 ))
17
+ # define APPLE_HAS_MEMSET_S 1
18
+ # elif (defined(TARGET_OS_TV ) && TARGET_OS_TV )
19
+ # define APPLE_HAS_MEMSET_S 1
20
+ # elif (defined(__WATCH_OS_VERSION_MIN_REQUIRED ) && (__WATCH_OS_VERSION_MIN_REQUIRED >= __WATCHOS_2_0 ))
21
+ # define APPLE_HAS_MEMSET_S 1
22
+ # elif (defined(TARGET_OS_VISION ) && TARGET_OS_VISION )
23
+ # define APPLE_HAS_MEMSET_S 1
24
+ # else
25
+ # define APPLE_HAS_MEMSET_S 0
26
+ # endif
13
27
#endif
14
28
15
29
#if (defined(__APPLE__ ) && defined(__MACH__ )) || defined(__linux__ ) || defined(__OpenBSD__ )
@@ -41,7 +55,7 @@ void Lib_Memzero0_memzero0(void *dst, uint64_t len) {
41
55
42
56
#ifdef _WIN32
43
57
SecureZeroMemory (dst , len_ );
44
- #elif defined(__APPLE__ ) && defined(__MACH__ ) && defined( MAC_OS_X_VERSION_MIN_REQUIRED ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 )
58
+ #elif defined(__APPLE__ ) && defined(__MACH__ ) && APPLE_HAS_MEMSET_S
45
59
memset_s (dst , len_ , 0 , len_ );
46
60
#elif (defined(__linux__ ) && !defined(LINUX_NO_EXPLICIT_BZERO )) || defined(__FreeBSD__ ) || defined(__OpenBSD__ )
47
61
explicit_bzero (dst , len_ );
@@ -52,7 +66,7 @@ void Lib_Memzero0_memzero0(void *dst, uint64_t len) {
52
66
#warning "Your platform does not support any safe implementation of memzero -- consider a pull request!"
53
67
volatile unsigned char * volatile dst_ = (volatile unsigned char * volatile ) dst ;
54
68
size_t i = 0U ;
55
- while (i < len )
69
+ while (i < len_ )
56
70
dst_ [i ++ ] = 0U ;
57
71
#endif
58
72
}
0 commit comments