1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: fix scanner overflowing string on numbers without newline

This commit is contained in:
Henrixounez 2019-08-06 11:37:14 +02:00 committed by Alexander Medvednikov
parent 7a7b5040e2
commit 347e59d604

View File

@ -128,7 +128,7 @@ fn (s mut Scanner) ident_dec_number() string {
start_pos := s.pos start_pos := s.pos
// scan integer part // scan integer part
for s.text[s.pos].is_digit() { for s.pos < s.text.len && s.text[s.pos].is_digit() {
s.pos++ s.pos++
} }
@ -141,9 +141,9 @@ fn (s mut Scanner) ident_dec_number() string {
} }
// scan fractional part // scan fractional part
if s.text[s.pos] == `.` { if s.pos < s.text.len && s.text[s.pos] == `.` {
s.pos++ s.pos++
for s.text[s.pos].is_digit() { for s.pos < s.text.len && s.text[s.pos].is_digit() {
s.pos++ s.pos++
} }
} }
@ -152,7 +152,7 @@ fn (s mut Scanner) ident_dec_number() string {
mut has_exponential_part := false mut has_exponential_part := false
if s.expect('e+', s.pos) || s.expect('e-', s.pos) { if s.expect('e+', s.pos) || s.expect('e-', s.pos) {
exp_start_pos := s.pos += 2 exp_start_pos := s.pos += 2
for s.text[s.pos].is_digit() { for s.pos < s.text.len && s.text[s.pos].is_digit() {
s.pos++ s.pos++
} }
if exp_start_pos == s.pos { if exp_start_pos == s.pos {
@ -162,7 +162,7 @@ fn (s mut Scanner) ident_dec_number() string {
} }
// error check: 1.23.4, 123.e+3.4 // error check: 1.23.4, 123.e+3.4
if s.text[s.pos] == `.` { if s.pos < s.text.len && s.text[s.pos] == `.` {
if has_exponential_part { if has_exponential_part {
s.error('exponential part should be integer') s.error('exponential part should be integer')
} }