mirror of
https://github.com/vlang/v.git
synced 2025-09-15 07:22:27 +03:00
examples: check array length before access (#21641)
This commit is contained in:
parent
1e86e06eb6
commit
096226bf05
1 changed files with 3 additions and 0 deletions
|
@ -37,6 +37,9 @@ fn (mut app App) service_auth(username string, password string) !string {
|
||||||
users := sql db {
|
users := sql db {
|
||||||
select from User where username == username
|
select from User where username == username
|
||||||
}!
|
}!
|
||||||
|
if users.len == 0 {
|
||||||
|
return error('user not found')
|
||||||
|
}
|
||||||
user := users.first()
|
user := users.first()
|
||||||
if user.username != username {
|
if user.username != username {
|
||||||
return error('user not found')
|
return error('user not found')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue