diff options
| author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-24 14:24:59 +0100 | 
|---|---|---|
| committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-24 14:24:59 +0100 | 
| commit | 6cb52deaad36f59738b6b4d203457a7f8d2d13e9 (patch) | |
| tree | 000cbd20c218ebd575a175b019298bd65228fe94 /src/core/common/SourceContextReader.cpp | |
| parent | 2e8432a2fd10f4cf5519628c7ab6e7c6e270ca15 (diff) | |
Fixed integer overflow bug in SourceContextReader, adapted TerminaLoggerTest
Diffstat (limited to 'src/core/common/SourceContextReader.cpp')
| -rw-r--r-- | src/core/common/SourceContextReader.cpp | 18 | 
1 files changed, 12 insertions, 6 deletions
diff --git a/src/core/common/SourceContextReader.cpp b/src/core/common/SourceContextReader.cpp index 65a6281..d5d379c 100644 --- a/src/core/common/SourceContextReader.cpp +++ b/src/core/common/SourceContextReader.cpp @@ -56,8 +56,8 @@ SourceContext SourceContextReader::readContext(CharReader &reader,  	size_t offs = 0;  	auto it = std::lower_bound(cache.begin(), cache.end(), start);  	if (it != cache.begin()) { -		it--;  // Go to the previous entry -		offs = *it; // Read the corresponding byte offset +		it--;        // Go to the previous entry +		offs = *it;  // Read the corresponding byte offset  		size_t line = it - cache.begin() + 1;  		ctx.startLine = line;  		ctx.endLine = line; @@ -182,17 +182,23 @@ SourceContext SourceContextReader::readContext(CharReader &reader,  		}  		// Update the relative position and length, set the "truncated" flags -		size_t us = static_cast<size_t>(s), ue = static_cast<size_t>(e); -		ctx.relPos = start - lineBufStart - us; -		ctx.relLen = std::min(ctx.relLen, ue - us); +		ctx.relPos = std::max<ssize_t>(0, start - lineBufStart - s); +		ctx.relLen = std::min<ssize_t>(ctx.relLen, e - s);  		ctx.truncatedStart = s > ts || lastLineStart < lineBufStart;  		ctx.truncatedEnd = e < te;  		// Copy the selected area to the output string -		ctx.text = std::string{&lineBuf[s], ue - us}; +		ctx.text = std::string{&lineBuf[s], static_cast<size_t>(e - s)};  	}  	return ctx;  } + +SourceContext SourceContextReader::readContext(CharReader &reader, +                                               const SourceRange &range, +                                               const std::string &filename) +{ +	return readContext(reader, range, MAX_MAX_CONTEXT_LENGTH, filename); +}  }  | 
