[compiler-rt] [scudo] Add `__scudo_get_info` symbol to export stats to a buffer. (PR #130273)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 6 08:13:23 PDT 2025


================
@@ -229,6 +229,15 @@ void ScopedString::append(const char *Format, ...) {
   va_end(Args);
 }
 
+size_t ScopedString::copyToBuffer(char *OutputBase, size_t OutputLength) {
+  if (OutputBase && OutputLength) {
+    const size_t Written = Min(length(), OutputLength - 1);
+    memcpy(OutputBase, data(), Written);
+    OutputBase[Written] = '\0';
+  }
+  return length() + 1;
----------------
piwicode wrote:

Here I tried to conform to existing APIs, they are a bit surprising, but it makes sense.

In combined.h, getStats uses that protocol, where the caller can provide a buffer, and if it is too small, the value gets truncated, and the caller knows it from the returned size. I reuse the same principle here.


https://github.com/llvm/llvm-project/pull/130273


More information about the llvm-commits mailing list