Skip to content

Commit

Permalink
refactor(scan.go): array index is out of bounds exits the for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
demoManito committed Mar 7, 2024
1 parent f17a752 commit 157d589
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,16 @@ func Scan(rows Rows, db *DB, mode ScanMode) {
db.scanIntoStruct(rows, elem, values, fields, joinFields)

if !update {
// array index is out of bounds, exits the for loop
if isArrayKind && reflectValue.Len() < int(db.RowsAffected) {
break
}

if !isPtr {
elem = elem.Elem()
}
if isArrayKind {
if reflectValue.Len() >= int(db.RowsAffected) {
reflectValue.Index(int(db.RowsAffected - 1)).Set(elem)
}
reflectValue.Index(int(db.RowsAffected - 1)).Set(elem)
} else {
reflectValue = reflect.Append(reflectValue, elem)
}
Expand Down

0 comments on commit 157d589

Please sign in to comment.