Skip to content

std::string_view encourages use-after-free; the Core Guidelines Checker doesn't complain #1038

Open
@kcc

Description

@kcc

[please excuse me if this has been discussed before]

#include <iostream>
#include <string>
#include <string_view>

int main() {
  std::string s = "Hellooooooooooooooo ";
  std::string_view sv = s + "World\n";
  std::cout << sv;
}

Here we have a heap-use-after-free bug which is easy to spot if you know what to look for, but the Core Guidelines Checker in VS++17 is silent (confirmed by @AndrewPardoe). This might be something missing in the checker, but I suspect that this is actually missing in the guidelines themselves. Moreover, I don't see how we can reject code like this w/o rejecting lots of other safe C++17 code.

Thoughts?

See also: https://bugs.llvm.org/show_bug.cgi?id=34729

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions