Commit e96fa717 by dan sinclair Committed by John Kessenich

Make sure source strings are terminated (#1641)

* Make sure source strings are terminated The source strings may or may not have a null terminator. We need to make sure we add one before outputting the source strings as we iterate over the c-str looking for the null terminator. * Review feedback
parent 6eab476e
...@@ -879,8 +879,11 @@ bool ProcessDeferred( ...@@ -879,8 +879,11 @@ bool ProcessDeferred(
intermediate.setHlslOffsets(); intermediate.setHlslOffsets();
if (messages & EShMsgDebugInfo) { if (messages & EShMsgDebugInfo) {
intermediate.setSourceFile(names[numPre]); intermediate.setSourceFile(names[numPre]);
for (int s = 0; s < numStrings; ++s) for (int s = 0; s < numStrings; ++s) {
intermediate.addSourceText(strings[numPre + s]); // The string may not be null-terminated, so make sure we provide
// the length along with the string.
intermediate.addSourceText(strings[numPre + s], lengths[numPre + s]);
}
} }
SetupBuiltinSymbolTable(version, profile, spvVersion, source); SetupBuiltinSymbolTable(version, profile, spvVersion, source);
......
...@@ -666,7 +666,7 @@ public: ...@@ -666,7 +666,7 @@ public:
void setSourceFile(const char* file) { if (file != nullptr) sourceFile = file; } void setSourceFile(const char* file) { if (file != nullptr) sourceFile = file; }
const std::string& getSourceFile() const { return sourceFile; } const std::string& getSourceFile() const { return sourceFile; }
void addSourceText(const char* text) { sourceText = sourceText + text; } void addSourceText(const char* text, size_t len) { sourceText.append(text, len); }
const std::string& getSourceText() const { return sourceText; } const std::string& getSourceText() const { return sourceText; }
const std::map<std::string, std::string>& getIncludeText() const { return includeText; } const std::map<std::string, std::string>& getIncludeText() const { return includeText; }
void addIncludeText(const char* name, const char* text, size_t len) { includeText[name].assign(text,len); } void addIncludeText(const char* name, const char* text, size_t len) { includeText[name].assign(text,len); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment