Skip to content
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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

firewave
Copy link
Collaborator

No description provided.

@@ -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 };
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants