math.big: fix validate_string and integer_from_regular_string (check for characters.len > 0, before accessing characters[0])

This commit is contained in:
Delyan Angelov 2025-07-23 15:04:48 +03:00
parent 735f8efb61
commit 43a4f3fa76
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -200,7 +200,7 @@ pub fn integer_from_radix(all_characters string, radix u32) !Integer {
@[direct_array_access] @[direct_array_access]
fn validate_string(characters string, radix u32) ! { fn validate_string(characters string, radix u32) ! {
sign_present := characters[0] == `+` || characters[0] == `-` sign_present := characters.len > 0 && (characters[0] == `+` || characters[0] == `-`)
start_index := if sign_present { 1 } else { 0 } start_index := if sign_present { 1 } else { 0 }
@ -261,7 +261,7 @@ fn integer_from_special_string(characters string, chunk_size int) Integer {
@[direct_array_access] @[direct_array_access]
fn integer_from_regular_string(characters string, radix u32) Integer { fn integer_from_regular_string(characters string, radix u32) Integer {
sign_present := characters[0] == `+` || characters[0] == `-` sign_present := characters.len > 0 && (characters[0] == `+` || characters[0] == `-`)
signum := if sign_present { signum := if sign_present {
if characters[0] == `-` { -1 } else { 1 } if characters[0] == `-` { -1 } else { 1 }