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

Tags : infinite loop #35

Open
malletjo opened this issue Aug 29, 2016 · 1 comment
Open

Tags : infinite loop #35

malletjo opened this issue Aug 29, 2016 · 1 comment

Comments

@malletjo
Copy link

Let me know if i'm wrong :

func getTags(obj reflect.Type, tags map[string]string, key string) {

    if obj.Kind() != reflect.Struct && obj.Kind() != reflect.Ptr {
        return
    }

    var tag string

    fieldsCount := obj.NumField()

    for i := 0; i < fieldsCount; i++ {
        structField := obj.Field(i)
        if structField.Anonymous && structField.Type.Kind() == reflect.Struct {
            getTags(obj, tags, key)
        } else {
            tag = structField.Tag.Get(key)
            if tag != "" {
                tags[structField.Name] = tag
            }
        }
    }
}

So if it's another struct, it will call itself with the same tag (obj)

Result in a infinite loop (overflow)

Possible solution: replaced with structField.Type

getTags(structField.Type, tags, key)

=== Step to reproduce ===

In a model

type Model struct {
    aranGO.Document
}

type Event struct {
    Model
    Title string        `json:"title"`
}

The embedded struct should cause the SO

@diegogub
Copy link
Owner

hi @malletjo , thanks for the report. I will check this now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants