From 0a3ef7b4ae02983ea3f986ba8211e7c6af9d254b Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 21 Jan 2019 15:33:59 -0500 Subject: Path simplification/hash mode, plus bug fixes (#788) * * Fix memory bug around expanding va_args - needed buffer to have space for terminating 0 * Fix problem with FileWriter defaults being globals, as memory they allocate, will only be freed after return from main - work around by making StdWriters RefObject derived, and kept in scope such the writers are destroyed before checks for leaks is found * Added SimplifyPathAndHash mode for CacheFileSystem - will simplify the path and see if simplified path is in cache before reading file (limiting amout of underlying file requests) * * Added calcReplaceChar * Renamed DefaultFileSystem to OSFileSystem * Made OSFileSystem convert windows \ to / on linux * Simplified logic for caching in CacheFileSystem. * Added pragma-once-c to add extra test, but also so there is an 'include' directory in preprocessor tests. * Small fixes in pragma once test. * Simplified cache handling path, so that paths/simplified paths area always added. * Improve naming of methods for different caches. --- source/core/slang-writer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source/core/slang-writer.cpp') diff --git a/source/core/slang-writer.cpp b/source/core/slang-writer.cpp index 433cc6992..a3222b0d2 100644 --- a/source/core/slang-writer.cpp +++ b/source/core/slang-writer.cpp @@ -28,6 +28,7 @@ SlangResult WriterHelper::print(const char* format, ...) SlangResult res = SLANG_OK; + // numChars is the amount of characters needed *not* including terminating 0 size_t numChars; { // Create a copy of args, as will be consumed by calcFormattedSize @@ -39,7 +40,8 @@ SlangResult WriterHelper::print(const char* format, ...) if (numChars > 0) { - char* appendBuffer = m_writer->beginAppendBuffer(numChars); + // We need to add 1 here, because calcFormatted, *requires* space for terminating 0 + char* appendBuffer = m_writer->beginAppendBuffer(numChars + 1); StringUtil::calcFormatted(format, args, numChars, appendBuffer); res = m_writer->endAppendBuffer(appendBuffer, numChars); } -- cgit v1.2.3