================
@@ -25,14 +25,19 @@ enum CXStringFlag {
   /// CXString contains a 'const char *' that it doesn't own.
   CXS_Unmanaged,
 
-  /// CXString contains a 'const char *' that it allocated with malloc().
-  CXS_Malloc,
+  /// CXString contains a 'CStringImpl' that it allocated with malloc().
+  CXS_MallocWithSize,
 
   /// CXString contains a CXStringBuf that needs to be returned to the
   /// CXStringPool.
   CXS_StringBuf
 };
 
+struct CStringImpl {
+  size_t length;
+  char buffer[sizeof(length)];
----------------
AaronBallman wrote:

Can you explain this a bit more? I would have expected this to be:
```
struct CStringImpl {
  size_t length;
  char buffer[];
};
```
with a flexible array member. This always allocates 4-8 bytes for the string 
length and runs into out-of-bounds array behavior because the final member is a 
fixed length array rather than a FAM.

https://github.com/llvm/llvm-project/pull/134551
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to