Passing a nullptr to memcpy is UB.
Details
Details
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
| lib/Support/StringSaver.cpp | ||
|---|---|---|
| 14 ↗ | (On Diff #161463) | Is it possible to reuse StringRef::copy(Allocator &) here? |
| lib/Support/StringSaver.cpp | ||
|---|---|---|
| 14 ↗ | (On Diff #161463) | Unfortunately, not, StringRef::copy will change the behavior. The StringRef returned here is null-terminated. |
Comment Actions
lg
| lib/Support/StringSaver.cpp | ||
|---|---|---|
| 14 ↗ | (On Diff #161463) | Hmm, that seems strange but out of the scope. |
Comment Actions
Why do we need to allocate memory in this case at all? I.e. why can't this just be:
if (S.empty())
return StringRef("", 0);
...