diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-05-05 03:46:42 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-04 12:46:42 -0700 |
| commit | ab3ac985479132856613d6dcc8b43f4a4ef8c6b7 (patch) | |
| tree | e4e911d10b8ec2866e7e408f9a10b51d743ee675 /source/core/slang-io.cpp | |
| parent | c0b6f59a6920a9efbb4ecc3b622529db484c64ef (diff) | |
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 <yonghe@outlook.com>
Diffstat (limited to 'source/core/slang-io.cpp')
| -rw-r--r-- | source/core/slang-io.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
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<char> 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) |
