isocpp / isocpp/CppCoreGuidelines

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

Open
#1,038 32 comments 27 reactions 1 assignee View on GitHub

@neilmacintosh is already working on this.

Since Oct 2, 2017.

Dominant language
CSS
Stars
45.3k
Forks
5.6k
PR merge metrics
No merged PRs in 30d

Description

[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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.