Skip to content

Commit 3548823

Browse files
authored
Revert "[libclang] Always Dup in createRef(StringRef) (#125020)"
This reverts commit e76739e.
1 parent 2ad8166 commit 3548823

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

clang/docs/ReleaseNotes.rst

-3
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,6 @@ clang-format
257257
libclang
258258
--------
259259

260-
- Fixed a buffer overflow in ``CXString`` implementation. The fix may result in
261-
increased memory allocation.
262-
263260
Code Completion
264261
---------------
265262

clang/tools/libclang/CXString.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,19 @@ CXString createRef(StringRef String) {
8787
if (String.empty())
8888
return createEmpty();
8989

90-
return createDup(String);
90+
// If the string is not nul-terminated, we have to make a copy.
91+
92+
// FIXME: This is doing a one past end read, and should be removed! For memory
93+
// we don't manage, the API string can become unterminated at any time outside
94+
// our control.
95+
96+
if (String.data()[String.size()] != 0)
97+
return createDup(String);
98+
99+
CXString Result;
100+
Result.data = String.data();
101+
Result.private_flags = (unsigned) CXS_Unmanaged;
102+
return Result;
91103
}
92104

93105
CXString createDup(StringRef String) {

0 commit comments

Comments
 (0)