fix panic caused by unsafe slice-casting operation in model.go

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2025-03-26 21:36:54 -04:00
parent a91f4b6af8
commit a44b9679aa
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

View File

@ -7,7 +7,6 @@ import (
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
"reflect"
"unsafe"
)
// Model - type which contains "static" methods like
@ -111,7 +110,12 @@ func (m *Model) Find(query interface{}, opts *options.FindOptionsBuilder) (*Quer
op: OP_FIND_ALL,
}
q, err := m.FindRaw(query, opts)
idoc := (*DocumentSlice)(unsafe.Pointer(qqv.Elem().UnsafeAddr()))
//idoc := (*DocumentSlice)(qqv.Elem().UnsafePointer())
idoc := make(DocumentSlice, 0)
for i := 0; i < qqv.Elem().Len(); i++ {
idoc = append(idoc, qqv.Elem().Index(i).Interface().(IDocument))
}
if err == nil {
rawRes := bson.A{}
err = q.All(context.TODO(), &rawRes)
@ -125,7 +129,7 @@ func (m *Model) Find(query interface{}, opts *options.FindOptionsBuilder) (*Quer
qq.reOrganize()
err = nil
}
for _, doc := range *idoc {
for _, doc := range idoc {
doc.setModel(*m)
}
}