-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
mitigated some -Wunsafe-buffer-usage
Clang warnings
#7038
base: main
Are you sure you want to change the base?
Conversation
@@ -6807,7 +6807,7 @@ class TestSymbolDatabase : public TestFixture { | |||
ASSERT(db); | |||
const Scope * bar = db->findScopeByName("bar"); | |||
ASSERT(bar != nullptr); | |||
constexpr unsigned int linenrs[2] = { 2, 1 }; |
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 wonder how this can cause -Wunsafe-buffer-usage
, which is supposed to be about using pointers with unknown size?
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.
It is about unsafe arithmetic and access of any pointers. std::array
provides bounds checking. This is about accessing linenrs
via operator[]
.
test/testsymboldatabase.cpp:6818:108: warning: unsafe buffer access [-Wunsafe-buffer-usage]
6818 | expected << "Function call on line " << tok->linenr() << " calls function on line " << linenrs[index] << std::endl;
| ^~~~~~~
But I saw a recent commit in LLVM which disables the warning in case it can statically determined that the index is in range (I cannot find it anymore). So I guess this PR should be deferred until Clang 20 is out.
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.
It is about unsafe arithmetic and access of any pointers.
std::array
provides bounds checking. [,..]
I don't think so: https://en.cppreference.com/w/cpp/container/array/operator_at
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.
It is about unsafe arithmetic and access of any pointers.
std::array
provides bounds checking. [,..]I don't think so: https://en.cppreference.com/w/cpp/container/array/operator_at
It does in the hardening mode - I forgot to mention that. Sorry about that.
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.
It does in the hardening mode - I forgot to mention that. Sorry about that.
But that should not affect the compiler warnings since it cannot be assumed that people will also run this code with the hardening mode at some point. Needs some looking into.
No description provided.