Skip to content

panic: nil struct pointer to MapTo #369

@DeadLockStarve

Description

@DeadLockStarve

Version

1.67.0

Describe the bug

This code should gracefully fail with an error, panics instead

To reproduce

package main

import (
    "log"

    "gopkg.in/ini.v1"
)

type Config struct {
    User string `ini:"user"`
    Pass string `ini:"pass"`
}

const iniData = `
user = alice
pass = secret
`

func main() {
    var cfg *Config

    f, err := ini.Load([]byte(iniData))
    if err != nil {
        log.Fatal(err)
    }

    if err := f.MapTo(&cfg); err != nil {
        log.Fatal(err)
    }

    log.Printf("User: %s, Pass: %s\n", cfg.User, cfg.Pass)
}

Expected behavior

Gracefully return an error

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions