builtin: fix undefined read s[0], from ''.is_lower() and ''.is_upper() in c7af2c2

This commit is contained in:
Delyan Angelov 2024-04-26 17:03:57 +03:00
parent c7af2c21d1
commit d66de0c514
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED

View file

@ -1524,7 +1524,7 @@ pub fn (s string) to_lower() string {
// Example: assert 'hello developer'.is_lower() == true
@[direct_array_access]
pub fn (s string) is_lower() bool {
if s[0].is_digit() {
if s.len > 0 && s[0].is_digit() {
return false
}
for i in 0 .. s.len {
@ -1558,7 +1558,7 @@ pub fn (s string) to_upper() string {
// Example: assert 'HELLO V'.is_upper() == true
@[direct_array_access]
pub fn (s string) is_upper() bool {
if s[0].is_digit() {
if s.len > 0 && s[0].is_digit() {
return false
}
for i in 0 .. s.len {