Add more const-correct C++ overloads.
libc++ actually provides overloads for all the standard C library stuff, so we just need to handle the POSIX and GNU extensions, of which there are just two more: memrchr and strcasestr. Bug: http://b/22768375 Test: builds Change-Id: Ie9ed1fbcc794e14a0c9bba13b5307ad677949613
This commit is contained in:
parent
57e07a150e
commit
df9a489b2b
|
@ -147,7 +147,7 @@ extern "C" void* __memcpy_chk_fail(void* /*dst*/, const void* /*src*/, size_t co
|
|||
|
||||
void* __memrchr_chk(const void* s, int c, size_t n, size_t actual_size) {
|
||||
__check_buffer_access("memrchr", "read from", n, actual_size);
|
||||
return memrchr(s, c, n);
|
||||
return memrchr(const_cast<void *>(s), c, n);
|
||||
}
|
||||
|
||||
// memset is performance-critical enough that we have assembler __memset_chk implementations.
|
||||
|
|
|
@ -38,6 +38,8 @@ size_t __strlcpy_chk(char*, const char*, size_t, size_t) __INTRODUCED_IN(17);
|
|||
size_t __strlcat_chk(char*, const char*, size_t, size_t) __INTRODUCED_IN(17);
|
||||
|
||||
#if defined(__BIONIC_FORTIFY)
|
||||
extern void* __memrchr_real(const void*, int, size_t) __RENAME(memrchr);
|
||||
|
||||
// These can share their implementation between gcc and clang with minimal
|
||||
// trickery...
|
||||
#if __ANDROID_API__ >= __ANDROID_API_J_MR1__
|
||||
|
@ -116,11 +118,11 @@ void* memchr(const void* const s __pass_object_size, int c, size_t n) __overload
|
|||
}
|
||||
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
void* memrchr(const void* const s __pass_object_size, int c, size_t n) __overloadable {
|
||||
void* __memrchr_fortify(const void* const __pass_object_size s, int c, size_t n) __overloadable {
|
||||
size_t bos = __bos(s);
|
||||
|
||||
if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
|
||||
return __call_bypassing_fortify(memrchr)(s, c, n);
|
||||
return __memrchr_real(s, c, n);
|
||||
}
|
||||
|
||||
return __memrchr_chk(s, c, n, bos);
|
||||
|
@ -231,7 +233,6 @@ char* strrchr(const char* const s __pass_object_size, int c) __overloadable {
|
|||
|
||||
#else // defined(__clang__)
|
||||
extern char* __strncpy_real(char*, const char*, size_t) __RENAME(strncpy);
|
||||
extern void* __memrchr_real(const void*, int, size_t) __RENAME(memrchr);
|
||||
extern size_t __strlcpy_real(char*, const char*, size_t)
|
||||
__RENAME(strlcpy);
|
||||
extern size_t __strlcat_real(char*, const char*, size_t)
|
||||
|
@ -261,7 +262,7 @@ void* memchr(const void* s __pass_object_size, int c, size_t n) {
|
|||
}
|
||||
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
void* memrchr(const void* s, int c, size_t n) {
|
||||
void* __memrchr_fortify(const void* s, int c, size_t n) {
|
||||
size_t bos = __bos(s);
|
||||
|
||||
if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
|
||||
|
@ -415,4 +416,26 @@ char* strrchr(const char* s, int c) {
|
|||
}
|
||||
#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR2__ */
|
||||
#endif /* defined(__clang__) */
|
||||
|
||||
#if __ANDROID_API__ >= __ANDROID_API_M__
|
||||
#if defined(__cplusplus)
|
||||
extern "C++" {
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
void* memrchr(void* const __pass_object_size s, int c, size_t n) {
|
||||
return __memrchr_fortify(s, c, n);
|
||||
}
|
||||
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
const void* memrchr(const void* const __pass_object_size s, int c, size_t n) {
|
||||
return __memrchr_fortify(s, c, n);
|
||||
}
|
||||
}
|
||||
#else
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
void* memrchr(const void* const __pass_object_size s, int c, size_t n) __overloadable {
|
||||
return __memrchr_fortify(s, c, n);
|
||||
}
|
||||
#endif
|
||||
#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */
|
||||
|
||||
#endif /* defined(__BIONIC_FORTIFY) */
|
||||
|
|
|
@ -43,7 +43,12 @@ __BEGIN_DECLS
|
|||
|
||||
void* memccpy(void* __dst, const void* __src, int __stop_char, size_t __n);
|
||||
void* memchr(const void* __s, int __ch, size_t __n) __attribute_pure__ __overloadable __RENAME_CLANG(memchr);
|
||||
#if defined(__cplusplus)
|
||||
extern "C++" void* memrchr(void* __s, int __ch, size_t __n) __RENAME(memrchr) __attribute_pure__;
|
||||
extern "C++" const void* memrchr(const void* __s, int __ch, size_t __n) __RENAME(memrchr) __attribute_pure__;
|
||||
#else
|
||||
void* memrchr(const void* __s, int __ch, size_t __n) __attribute_pure__ __overloadable __RENAME_CLANG(memrchr);
|
||||
#endif
|
||||
int memcmp(const void* __lhs, const void* __rhs, size_t __n) __attribute_pure__;
|
||||
void* memcpy(void*, const void*, size_t)
|
||||
__overloadable __RENAME_CLANG(memcpy);
|
||||
|
@ -81,7 +86,12 @@ char* strcat(char* __dst, const char* __src) __overloadable __RENAME_CLANG(strca
|
|||
char* strdup(const char* __s);
|
||||
|
||||
char* strstr(const char* __haystack, const char* __needle) __attribute_pure__;
|
||||
#if defined(__cplusplus)
|
||||
extern "C++" char* strcasestr(char*, const char*) __RENAME(strcasestr) __attribute_pure__;
|
||||
extern "C++" const char* strcasestr(const char*, const char*) __RENAME(strcasestr) __attribute_pure__;
|
||||
#else
|
||||
char* strcasestr(const char* __haystack, const char* __needle) __attribute_pure__;
|
||||
#endif
|
||||
char* strtok(char* __s, const char* __delimiter);
|
||||
char* strtok_r(char* __s, const char* __delimiter, char** __pos_ptr);
|
||||
|
||||
|
|
Loading…
Reference in New Issue