Commit 010e93fe by John Kessenich

Merge pull request #228 from Qining/fix-infinite-loop-due-to-eof-missing

Scanner/PP: Fix the infinite loop when an input file lacks EOF
parents ba00f67d 94a89d51
noEOF
\ No newline at end of file
...@@ -13,3 +13,4 @@ preprocessor.simple.vert ...@@ -13,3 +13,4 @@ preprocessor.simple.vert
preprocessor.success_if_parse_would_fail.vert preprocessor.success_if_parse_would_fail.vert
preprocessor.defined.vert preprocessor.defined.vert
preprocessor.many.endif.vert preprocessor.many.endif.vert
preprocessor.eof_missing.vert
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
TInputScanner(int n, const char* const s[], size_t L[], const char* const* names = nullptr, int b = 0, int f = 0, bool single = false) : TInputScanner(int n, const char* const s[], size_t L[], const char* const* names = nullptr, int b = 0, int f = 0, bool single = false) :
numSources(n), numSources(n),
sources(reinterpret_cast<const unsigned char* const *>(s)), // up to this point, common usage is "char*", but now we need positive 8-bit characters sources(reinterpret_cast<const unsigned char* const *>(s)), // up to this point, common usage is "char*", but now we need positive 8-bit characters
lengths(L), currentSource(0), currentChar(0), stringBias(b), finale(f), singleLogical(single) lengths(L), currentSource(0), currentChar(0), stringBias(b), finale(f), singleLogical(single), endOfFileReached(false)
{ {
loc = new TSourceLoc[numSources]; loc = new TSourceLoc[numSources];
for (int i = 0; i < numSources; ++i) { for (int i = 0; i < numSources; ++i) {
...@@ -81,10 +81,8 @@ public: ...@@ -81,10 +81,8 @@ public:
// retrieve the next character and advance one character // retrieve the next character and advance one character
int get() int get()
{ {
if (currentSource >= numSources)
return EndOfInput;
int ret = peek(); int ret = peek();
if (ret == EndOfInput) return ret;
++loc[currentSource].column; ++loc[currentSource].column;
++logicalSourceLoc.column; ++logicalSourceLoc.column;
if (ret == '\n') { if (ret == '\n') {
...@@ -101,8 +99,10 @@ public: ...@@ -101,8 +99,10 @@ public:
// retrieve the next character, no advance // retrieve the next character, no advance
int peek() int peek()
{ {
if (currentSource >= numSources) if (currentSource >= numSources) {
endOfFileReached = true;
return EndOfInput; return EndOfInput;
}
// Make sure we do not read off the end of a string. // Make sure we do not read off the end of a string.
// N.B. Sources can have a length of 0. // N.B. Sources can have a length of 0.
int sourceToRead = currentSource; int sourceToRead = currentSource;
...@@ -122,6 +122,9 @@ public: ...@@ -122,6 +122,9 @@ public:
// go back one character // go back one character
void unget() void unget()
{ {
// Do not roll back once we've reached the end of the file.
if (endOfFileReached) return;
if (currentChar > 0) { if (currentChar > 0) {
--currentChar; --currentChar;
--loc[currentSource].column; --loc[currentSource].column;
...@@ -251,6 +254,10 @@ protected: ...@@ -251,6 +254,10 @@ protected:
TSourceLoc logicalSourceLoc; TSourceLoc logicalSourceLoc;
bool singleLogical; // treats the strings as a single logical string. bool singleLogical; // treats the strings as a single logical string.
// locations will be reported from the first string. // locations will be reported from the first string.
// set to true once peak() returns EndOfFile, so that we won't roll back
// once we've reached EndOfFile.
bool endOfFileReached;
}; };
} // end namespace glslang } // end namespace glslang
......
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