From ab3ac985479132856613d6dcc8b43f4a4ef8c6b7 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Fri, 5 May 2023 03:46:42 +0800 Subject: Add SLANG_ASSUME and use it in release asserts (#2859) * Remove UNREACHABLE * formatting * Remove unused SLANG_EXPECT macros * Add SLANG_ASSUME and use it in release asserts * Reassure GCC that we are using memcpy responsibly --------- Co-authored-by: Yong He --- source/core/slang-io.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source/core/slang-io.cpp') diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index 81f0cbf87..8a2243b15 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -124,9 +124,11 @@ namespace Slang builder << "/tmp/" << inPrefix << "-XXXXXX"; List buffer; - buffer.setCount(builder.getLength() + 1); - ::memcpy(buffer.getBuffer(), builder.getBuffer(), builder.getLength()); - buffer[builder.getLength()] = 0; + auto copySize = builder.getLength(); + buffer.setCount(copySize + 1); + SLANG_ASSERT(copySize < PTRDIFF_MAX); // Shhh gcc, it's ok, we're not copying 9000 Petabytes + ::memcpy(buffer.getBuffer(), builder.getBuffer(), copySize); + buffer[copySize] = 0; int handle = mkstemp(buffer.getBuffer()); if (handle == -1) -- cgit v1.2.3