[llvm-bugs] [Bug 45561] New: Pointer to local variable returned in llvm/lib/TextAPI/MachO/TextStub.cpp
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Apr 15 13:31:22 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=45561
Bug ID: 45561
Summary: Pointer to local variable returned in
llvm/lib/TextAPI/MachO/TextStub.cpp
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Support Libraries
Assignee: unassignedbugs at nondot.org
Reporter: m.gehre at gmx.de
CC: llvm-bugs at lists.llvm.org
llvm-project/llvm/lib/TextAPI/MachO/TextStub.cpp:416:14: warning: returning
address of local temporary object [-Wreturn-stack-address]
The code there is
```
static StringRef input(StringRef Scalar, void *, Target &Value) {
auto Result = Target::create(Scalar);
if (!Result)
return toString(Result.takeError());
```
The `toString` function returns a temporary std::string, so the return value of
`input` refers to a then-destroyed temporary std::string.
Was detected by clang 10 or later by adding `[[gsl::Pointer]]` to StringRef
(see https://reviews.llvm.org/D66443).
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200415/b34d99d1/attachment.html>
More information about the llvm-bugs
mailing list