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
This commit is contained in:
dan sinclair 2019-01-07 11:47:37 -05:00 committed by John Kessenich
parent 6eab476e5a
commit e96fa717d3
2 changed files with 6 additions and 3 deletions

View File

@ -879,8 +879,11 @@ bool ProcessDeferred(
intermediate.setHlslOffsets();
if (messages & EShMsgDebugInfo) {
intermediate.setSourceFile(names[numPre]);
for (int s = 0; s < numStrings; ++s)
intermediate.addSourceText(strings[numPre + s]);
for (int s = 0; s < numStrings; ++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);

View File

@ -666,7 +666,7 @@ public:
void setSourceFile(const char* file) { if (file != nullptr) sourceFile = file; }
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::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); }