-
Notifications
You must be signed in to change notification settings - Fork 15k
[asan] Avoid -Wpointer-bool-conversion warning by comparing to nullptr #164906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The current code may trigger a compiler warning: ``` address of function 'wcsnlen' will always evaluate to 'true' [-Wpointer-bool-conversion] ``` Fix this by casting. The same fix is applied to strnlen for future-proofing.
|
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Thurston Dang (thurstond) ChangesThe current code may trigger a compiler warning: Fix this by casting. The same fix is applied to strnlen for future-proofing. Full diff: https://github.com/llvm/llvm-project/pull/164906.diff 1 Files Affected:
diff --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp
index 0f613f0fdc30b..8643271e89d70 100644
--- a/compiler-rt/lib/asan/asan_interceptors.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors.cpp
@@ -58,7 +58,7 @@ namespace __asan {
static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
#if SANITIZER_INTERCEPT_STRNLEN
- if (REAL(strnlen))
+ if (static_cast<bool>(REAL(strnlen)))
return REAL(strnlen)(s, maxlen);
# endif
return internal_strnlen(s, maxlen);
@@ -66,7 +66,7 @@ static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
static inline uptr MaybeRealWcsnlen(const wchar_t* s, uptr maxlen) {
# if SANITIZER_INTERCEPT_WCSNLEN
- if (REAL(wcsnlen))
+ if (static_cast<bool>(REAL(wcsnlen)))
return REAL(wcsnlen)(s, maxlen);
# endif
return internal_wcsnlen(s, maxlen);
|
|
|
||
| static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) { | ||
| #if SANITIZER_INTERCEPT_STRNLEN | ||
| if (REAL(strnlen)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not != nullptr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried there might be edge cases where REAL(strnlen) is defined to be zero but not a pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is that possible if we call it in the line below? You can't call an integer, and it still needs to typecheck?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Australia, you can call 000 for emergency services.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to compare to nullptr: 220c33c
llvm#164906 converted bool-pointer compare into -Wtautological-pointer-compare.
#164906 converted a -Wpointer-bool-conversion warning into a -Wtautological-pointer-compare warning. Avoid both by using the bool cast.
llvm/llvm-project#164906 converted a -Wpointer-bool-conversion warning into a -Wtautological-pointer-compare warning. Avoid both by using the bool cast.
llvm#164906) The current code may trigger a compiler warning: ``` address of function 'wcsnlen' will always evaluate to 'true' [-Wpointer-bool-conversion] ``` Fix this by comparing to nullptr. The same fix is applied to strnlen for future-proofing.
llvm#164906 converted a -Wpointer-bool-conversion warning into a -Wtautological-pointer-compare warning. Avoid both by using the bool cast.
llvm#164906) The current code may trigger a compiler warning: ``` address of function 'wcsnlen' will always evaluate to 'true' [-Wpointer-bool-conversion] ``` Fix this by comparing to nullptr. The same fix is applied to strnlen for future-proofing.
llvm#164906 converted a -Wpointer-bool-conversion warning into a -Wtautological-pointer-compare warning. Avoid both by using the bool cast.
llvm#164906) The current code may trigger a compiler warning: ``` address of function 'wcsnlen' will always evaluate to 'true' [-Wpointer-bool-conversion] ``` Fix this by comparing to nullptr. The same fix is applied to strnlen for future-proofing.
llvm#164906 converted a -Wpointer-bool-conversion warning into a -Wtautological-pointer-compare warning. Avoid both by using the bool cast.
The current code may trigger a compiler warning:
Fix this by comparing to nullptr. The same fix is applied to strnlen for future-proofing.