Skip to content

Commit 43a4f3f

Browse files
committed
math.big: fix validate_string and integer_from_regular_string (check for characters.len > 0, before accessing characters[0])
1 parent 735f8ef commit 43a4f3f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎vlib/math/big/integer.v‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub fn integer_from_radix(all_characters string, radix u32) !Integer {
200200

201201
@[direct_array_access]
202202
fn validate_string(characters string, radix u32) ! {
203-
sign_present := characters[0] == `+` || characters[0] == `-`
203+
sign_present := characters.len > 0 && (characters[0] == `+` || characters[0] == `-`)
204204

205205
start_index := if sign_present { 1 } else { 0 }
206206

@@ -261,7 +261,7 @@ fn integer_from_special_string(characters string, chunk_size int) Integer {
261261

262262
@[direct_array_access]
263263
fn integer_from_regular_string(characters string, radix u32) Integer {
264-
sign_present := characters[0] == `+` || characters[0] == `-`
264+
sign_present := characters.len > 0 && (characters[0] == `+` || characters[0] == `-`)
265265

266266
signum := if sign_present {
267267
if characters[0] == `-` { -1 } else { 1 }

0 commit comments

Comments
 (0)