parse_execution: Check array index before using it

This commit is contained in:
Fabian Homborg 2018-11-14 11:24:55 +01:00
parent 7437f82d92
commit 534f694cee

View file

@ -1387,7 +1387,7 @@ int parse_execution_context_t::line_offset_of_character_at_offset(size_t offset)
const wchar_t *str = pstree->src.c_str(); const wchar_t *str = pstree->src.c_str();
if (offset > cached_lineno_offset) { if (offset > cached_lineno_offset) {
size_t i; size_t i;
for (i = cached_lineno_offset; str[i] != L'\0' && i < offset; i++) { for (i = cached_lineno_offset; i < offset && str[i] != L'\0'; i++) {
// Add one for every newline we find in the range [cached_lineno_offset, offset). // Add one for every newline we find in the range [cached_lineno_offset, offset).
if (str[i] == L'\n') { if (str[i] == L'\n') {
cached_lineno_count++; cached_lineno_count++;