[clang] [libclang] Always Dup in createRef(StringRef) (PR #125020)

Vitaly Buka via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 12 22:03:37 PST 2025


https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/125020

>From 10af91096eda7eb2b7f07cf239f53ac3af456566 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Wed, 29 Jan 2025 19:59:21 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/tools/libclang/CXString.cpp | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/clang/tools/libclang/CXString.cpp b/clang/tools/libclang/CXString.cpp
index 5e427957a1092..aaa8f8eeb67a1 100644
--- a/clang/tools/libclang/CXString.cpp
+++ b/clang/tools/libclang/CXString.cpp
@@ -87,19 +87,7 @@ CXString createRef(StringRef String) {
   if (String.empty())
     return createEmpty();
 
-  // If the string is not nul-terminated, we have to make a copy.
-
-  // FIXME: This is doing a one past end read, and should be removed! For memory
-  // we don't manage, the API string can become unterminated at any time outside
-  // our control.
-
-  if (String.data()[String.size()] != 0)
-    return createDup(String);
-
-  CXString Result;
-  Result.data = String.data();
-  Result.private_flags = (unsigned) CXS_Unmanaged;
-  return Result;
+  return createDup(String);
 }
 
 CXString createDup(StringRef String) {

>From 278a41b390adde06ab3becf07cabe9abbe1dce9e Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Wed, 12 Feb 2025 22:03:27 -0800
Subject: [PATCH 2/2] quotes

Created using spr 1.3.4
---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 141319fd7c2d2..c5a49ebebd598 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -252,7 +252,7 @@ clang-format
 libclang
 --------
 
-- Fixed a buffer overflow in CXString implementation. This fix may result in
+- Fixed a buffer overflow in ``CXString`` implementation. This fix may result in
   increased memory allocation.
 
 Code Completion



More information about the cfe-commits mailing list