summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/core/slang-blob.h1
-rw-r--r--source/core/slang-io.cpp3
-rw-r--r--source/core/slang-test-tool-util.cpp19
-rw-r--r--source/core/slang-test-tool-util.h2
-rw-r--r--source/core/unix/slang-unix-process.cpp3
-rw-r--r--source/slang/slang-emit-spirv.cpp1
-rw-r--r--tools/gfx/vulkan/vk-module.h2
-rw-r--r--tools/render-test/slang-support.cpp6
-rw-r--r--tools/slang-embed/slang-embed.cpp2
-rw-r--r--tools/slang-generate/main.cpp6
-rw-r--r--tools/slang-test/test-context.cpp5
11 files changed, 35 insertions, 15 deletions
diff --git a/source/core/slang-blob.h b/source/core/slang-blob.h
index 7a2c4d967..e678680aa 100644
--- a/source/core/slang-blob.h
+++ b/source/core/slang-blob.h
@@ -129,6 +129,7 @@ public:
/// Allocate size including a 0 byte at `size`.
void* allocateTerminated(size_t size)
{
+ SLANG_ASSUME(size != std::numeric_limits<size_t>::max());
uint8_t* data = (uint8_t*)allocate(size + 1);
data[size] = 0;
m_sizeInBytes = size;
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 8a2243b15..4ef5ecc2d 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -126,7 +126,8 @@ namespace Slang
List<char> buffer;
auto copySize = builder.getLength();
buffer.setCount(copySize + 1);
- SLANG_ASSERT(copySize < PTRDIFF_MAX); // Shhh gcc, it's ok, we're not copying 9000 Petabytes
+ // Satisfy GCC
+ SLANG_ASSUME(copySize < PTRDIFF_MAX && copySize > 0);
::memcpy(buffer.getBuffer(), builder.getBuffer(), copySize);
buffer[copySize] = 0;
diff --git a/source/core/slang-test-tool-util.cpp b/source/core/slang-test-tool-util.cpp
index 68673a29f..487ea89ac 100644
--- a/source/core/slang-test-tool-util.cpp
+++ b/source/core/slang-test-tool-util.cpp
@@ -103,12 +103,21 @@ static SlangResult _addCUDAPrelude(const String& rootPath, slang::IGlobalSession
String parentPath;
SLANG_RETURN_ON_FAIL(getExeDirectoryPath(inExePath, parentPath));
- // From directory to the root is ../../..
- // Work out the relative path to the root
- String rootRelPath = Path::combine(parentPath, "../../../");
+ // Work out the relative path to the root, we will search upwards until we
+ // find a directory containing 'prelude/slang-cpp-prelude.h'
+ String rootRelPath;
+ SLANG_RETURN_ON_FAIL(Path::getCanonical(parentPath, rootRelPath));
+ do
+ {
+ if(File::exists(Path::combine(rootRelPath, "prelude/slang-cpp-prelude.h")))
+ break;
+
+ rootRelPath = Path::getParentDirectory(rootRelPath);
+ if(rootRelPath == "")
+ return SLANG_E_NOT_AVAILABLE;
+ } while(1);
- // We want the absolute path to the root
- SLANG_RETURN_ON_FAIL(Path::getCanonical(rootRelPath, outExePath));
+ outExePath = std::move(rootRelPath);
return SLANG_OK;
}
diff --git a/source/core/slang-test-tool-util.h b/source/core/slang-test-tool-util.h
index 186003a62..1e56500d2 100644
--- a/source/core/slang-test-tool-util.h
+++ b/source/core/slang-test-tool-util.h
@@ -53,7 +53,7 @@ struct TestToolUtil
/// Given the exePath, give return the absolute path to the directory the exe is in
static SlangResult getExeDirectoryPath(const char* exePath, String& outExeDirectoryPath);
- /// Sets the default preludes on the session based on the executable path
+ /// Sets the default preludes on the session based on an explicit path
static SlangResult setSessionDefaultPreludeFromRootPath(const String& rootPath, slang::IGlobalSession* session);
/// Calculates the path that is the combination of parentPath, and relPath
diff --git a/source/core/unix/slang-unix-process.cpp b/source/core/unix/slang-unix-process.cpp
index 3ab113d83..ee5484fd8 100644
--- a/source/core/unix/slang-unix-process.cpp
+++ b/source/core/unix/slang-unix-process.cpp
@@ -516,7 +516,8 @@ static int pipeCLOEXEC(int pipefd[2])
// Signal the failure to our parent
int execErr = errno;
- ::write(execWatchPipe[1], &execErr, sizeof(execErr));
+ if(::write(execWatchPipe[1], &execErr, sizeof(execErr)))
+ fprintf(stderr, "error: `exec` watch pipe write failed\n");
// NOTE! Because we have dup2 into STDERR_FILENO, this error will *not* generally appear on
// the terminal but in the stderrPipe.
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 3274c3223..0eae87a10 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -323,6 +323,7 @@ struct SpvLiteralBits
char* dst = (char*)(result.value.getBuffer());
// Copy the text
+ SLANG_ASSUME(textCount >= 0);
memcpy(dst, text.begin(), textCount);
// Set terminating 0, and remaining buffer 0s
diff --git a/tools/gfx/vulkan/vk-module.h b/tools/gfx/vulkan/vk-module.h
index 5e67a0a7f..97a0c8aba 100644
--- a/tools/gfx/vulkan/vk-module.h
+++ b/tools/gfx/vulkan/vk-module.h
@@ -13,7 +13,7 @@
#define VK_NO_PROTOTYPES
-#include <vulkan/include/vulkan/vulkan.h>
+#include <vulkan/vulkan.h>
// Undef xlib macros
#ifdef Always
diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp
index d9d8ddb45..82d292cee 100644
--- a/tools/render-test/slang-support.cpp
+++ b/tools/render-test/slang-support.cpp
@@ -348,7 +348,11 @@ void ShaderCompilerUtil::Output::reset()
fseek(sourceFile, 0, SEEK_SET);
outSourceText.setCount(sourceSize + 1);
- fread(outSourceText.getBuffer(), sourceSize, 1, sourceFile);
+ if(fread(outSourceText.getBuffer(), sourceSize, 1, sourceFile) != 1)
+ {
+ fprintf(stderr, "error: failed to read from '%s'\n", inSourcePath.getBuffer());
+ return SLANG_FAIL;
+ }
fclose(sourceFile);
outSourceText[sourceSize] = 0;
diff --git a/tools/slang-embed/slang-embed.cpp b/tools/slang-embed/slang-embed.cpp
index 80ee6c237..0edc13683 100644
--- a/tools/slang-embed/slang-embed.cpp
+++ b/tools/slang-embed/slang-embed.cpp
@@ -213,7 +213,7 @@ struct App
FILE* outputFile = fopen(outputPath, "w");
ScopedFile outputFileCleanup(outputFile);
- if( !outputPath )
+ if( !outputFile )
{
fprintf(stderr, "%s: error: failed to open '%s' for reading\n", appName, outputPath);
exit(1);
diff --git a/tools/slang-generate/main.cpp b/tools/slang-generate/main.cpp
index 7d07cd613..af81385dd 100644
--- a/tools/slang-generate/main.cpp
+++ b/tools/slang-generate/main.cpp
@@ -809,7 +809,11 @@ SourceFile* parseSourceFile(const String& path)
fseek(inputStream, 0, SEEK_SET);
char* input = (char*)malloc(inputSize + 1);
- fread(input, inputSize, 1, inputStream);
+ if(fread(input, inputSize, 1, inputStream) != 1)
+ {
+ fprintf(stderr, "unable to read input file: %s\n", path.getBuffer());
+ return nullptr;
+ }
input[inputSize] = 0;
char const* inputEnd = input + inputSize;
diff --git a/tools/slang-test/test-context.cpp b/tools/slang-test/test-context.cpp
index 39f5c92ed..b1be005cb 100644
--- a/tools/slang-test/test-context.cpp
+++ b/tools/slang-test/test-context.cpp
@@ -122,9 +122,8 @@ TestContext::InnerMainFunc TestContext::getInnerMainFunc(const String& dirPath,
sharedLibToolBuilder.append(name);
sharedLibToolBuilder.append("-tool");
- StringBuilder builder;
- SharedLibrary::appendPlatformFileName(sharedLibToolBuilder.getUnownedSlice(), builder);
- String path = Path::combine(dirPath, builder);
+ StringBuilder path;
+ SharedLibrary::appendPlatformFileName(sharedLibToolBuilder.getUnownedSlice(), path);
DefaultSharedLibraryLoader* loader = DefaultSharedLibraryLoader::getSingleton();