Merge "Move fortified memset() up with memcpy()/memmove()." into main am: e555475dd0
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3531475
Change-Id: I36cb8fa2a929d5e4cf52600a0c881162ec565ae5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/libc/include/bits/fortify/string.h b/libc/include/bits/fortify/string.h
index 0b4b70b..4ec356f 100644
--- a/libc/include/bits/fortify/string.h
+++ b/libc/include/bits/fortify/string.h
@@ -61,6 +61,20 @@
}
#endif
+/* TODO: remove __clang_warning_if when https://issuetracker.google.com/400937647 is fixed. */
+__BIONIC_FORTIFY_INLINE
+void* _Nonnull memset(void* _Nonnull const s __pass_object_size0, int c, size_t n)
+ __diagnose_as_builtin(__builtin_memset, 1, 2, 3)
+ __overloadable
+ /* If you're a user who wants this warning to go away: use `(&memset)(foo, bar, baz)`. */
+ __clang_warning_if(c && !n, "'memset' will set 0 bytes; maybe the arguments got flipped?") {
+#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
+ return __builtin___memset_chk(s, c, n, __bos0(s));
+#else
+ return __builtin_memset(s, c, n);
+#endif
+}
+
#if defined(__USE_GNU)
#if __ANDROID_API__ >= 30
__BIONIC_FORTIFY_INLINE
@@ -127,19 +141,6 @@
}
#endif
-/* No diag -- clang diagnoses misuses of this on its own. */
-__BIONIC_FORTIFY_INLINE
-void* _Nonnull memset(void* _Nonnull const s __pass_object_size0, int c, size_t n) __overloadable
- __diagnose_as_builtin(__builtin_memset, 1, 2, 3)
- /* If you're a user who wants this warning to go away: use `(&memset)(foo, bar, baz)`. */
- __clang_warning_if(c && !n, "'memset' will set 0 bytes; maybe the arguments got flipped?") {
-#if __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
- return __builtin___memset_chk(s, c, n, __bos0(s));
-#else
- return __builtin_memset(s, c, n);
-#endif
-}
-
#if __ANDROID_API__ >= 23 && __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED
__BIONIC_FORTIFY_INLINE
void* _Nullable memchr(const void* _Nonnull const s __pass_object_size, int c, size_t n) __overloadable {