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

[Clang-Tidy] Create bugprone-string-view-data-usage check #80854

Closed
PiotrZSL opened this issue Feb 6, 2024 · 1 comment · Fixed by #83716
Closed

[Clang-Tidy] Create bugprone-string-view-data-usage check #80854

PiotrZSL opened this issue Feb 6, 2024 · 1 comment · Fixed by #83716
Assignees
Labels
check-request Request for a new check in clang-tidy clang-tidy

Comments

@PiotrZSL
Copy link
Member

PiotrZSL commented Feb 6, 2024

I'm adding this here so, i wouldn't forget.
I run into this issue personally.

Background:

void something(std::string s);

int main()
{
   std::string_view sv("something");
   sv = sv.substr(0, 5);
   something(sv.data());
}

Because constructor in std::string that take std::string_view is implicit, this forces developer to be more ... productive.
Problem is that in such case .data() may not be null terminated or may not point to proper string.

Enforce:
Find all calls to std::string_view::data, that are passed to method/function, where other parameter isnt an std::string_view::length/size.

@PiotrZSL PiotrZSL added clang-tidy check-request Request for a new check in clang-tidy labels Feb 6, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 6, 2024

@llvm/issue-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)

I'm adding this here so, i wouldn't forget. I run into this issue personally.

Background:

void something(std::string s);

int main()
{
   std::string_view sv("something");
   sv = sv.substr(0, 5);
   something(sv.data());
}

Because constructor in std::string that take std::string_view is implicit, this forces developer to be more ... productive.
Problem is that in such case .data() may not be null terminated or may not point to proper string.

Enforce:
Find all calls to std::string_view::data, that are passed to method/function, where other parameter isnt an std::string_view::length/size.

@PiotrZSL PiotrZSL changed the title Create bugprone-string-view-data-usage check [Clang-Tidy] Create bugprone-string-view-data-usage check Feb 6, 2024
@PiotrZSL PiotrZSL self-assigned this Feb 15, 2024
PiotrZSL added a commit that referenced this issue Mar 19, 2024
)

This check identifies suspicious usages of std::string_view::data() that
could lead to reading out-of-bounds data due to inadequate or incorrect
string null termination.

Closes #80854
chencha3 pushed a commit to chencha3/llvm-project that referenced this issue Mar 23, 2024
…m#83716)

This check identifies suspicious usages of std::string_view::data() that
could lead to reading out-of-bounds data due to inadequate or incorrect
string null termination.

Closes llvm#80854
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
check-request Request for a new check in clang-tidy clang-tidy
Projects
None yet
2 participants