Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EDIT - Increase Depth Limit in ptrFromMapping #1360

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions queries/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const (
loadMethodPrefix = "Load"
relationshipStructName = "R"
loaderStructName = "L"
sentinel = uint64(255)
sentinel = uint64(4095)
depthShift = 12
)

// BindP executes the query and inserts the
Expand Down Expand Up @@ -354,8 +355,9 @@ func ptrFromMapping(val reflect.Value, mapping uint64, addressOf bool) reflect.V
var ignored interface{}
return reflect.ValueOf(&ignored)
}
for i := 0; i < 8; i++ {
v := (mapping >> uint(i*8)) & sentinel
// I am not confident that this replacing the magic number 8 with `depthShift` is the correct solution.
for i := 0; i < depthShift; i++ {
v := (mapping >> uint(i*depthShift)) & sentinel

if v == sentinel {
if addressOf && val.Kind() != reflect.Ptr {
Expand Down Expand Up @@ -407,11 +409,11 @@ func makeStructMappingHelper(typ reflect.Type, prefix string, current uint64, de
}

if recurse {
makeStructMappingHelper(f.Type, tag, current|uint64(i)<<depth, depth+8, fieldMaps)
makeStructMappingHelper(f.Type, tag, current|uint64(i)<<depth, depth+depthShift, fieldMaps)
continue
}

fieldMaps[tag] = current | (sentinel << (depth + 8)) | (uint64(i) << depth)
fieldMaps[tag] = current | (sentinel << (depth + depthShift)) | (uint64(i) << depth)
}
}

Expand Down
Loading