From 79e4e97ad591a30398b8a105a1e2d42bbb2914f9 Mon Sep 17 00:00:00 2001 From: Gnorkus Date: Thu, 4 Dec 2025 11:31:13 -0500 Subject: [PATCH] Add check for string size in ConvertToC function Check for non-zero string size before copying. --- cscore/src/main/native/cpp/c_util.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cscore/src/main/native/cpp/c_util.h b/cscore/src/main/native/cpp/c_util.h index a81f4287168..e0db7e853d9 100644 --- a/cscore/src/main/native/cpp/c_util.h +++ b/cscore/src/main/native/cpp/c_util.h @@ -13,8 +13,10 @@ namespace cs { inline void ConvertToC(struct WPI_String* output, std::string_view str) { - char* write = WPI_AllocateString(output, str.size()); - std::memcpy(write, str.data(), str.size()); + size_t n = str.size(); + char* write = WPI_AllocateString(output, n); + if (n>0) + std::memcpy(write, str.data(), n); } } // namespace cs