Skip to content

panic: slice of struct pointers #370

Closed

Description

@DeadLockStarve

Version

1.67.0

Describe the bug

The library doesn't treat correctly slices of struct pointers

To reproduce

package main

import (
	"log"

	"gopkg.in/ini.v1"
)

const iniData = `[Peer]
PublicKey    = pubClientKey
PresharedKey = psKey
AllowedIPs   = 10.2.0.2/32,fd00:2::2/128

[Peer]
PublicKey    = pubClientKey2
PresharedKey = psKey2
AllowedIPs   = 10.2.0.3/32,fd00:2::3/128
`

type Peer struct {
	PublicKey    string
	PresharedKey string
	AllowedIPs   []string `delim:","`
}

type Config struct {
	Peers []*Peer `ini:"Peer,nonunique"`
}

func main() {
	cfgFile, err := ini.LoadSources(ini.LoadOptions{AllowNonUniqueSections: true}, []byte(iniData))
	if err != nil {
		log.Fatal(err)
	}

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

Expected behavior

Should unmarshal correctly, panics instead

Code of Conduct

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

Activity

  1. added a commit that references this issue on Apr 14, 2026
    0575c4d
  2. unknwon commented on Nov 11, 2026

    @unknwon
    Member

    Fixed in v1.68.0 by PR 396: a []*T field with the nonunique tag maps each section into a new T. A nonunique slice of non-struct pointers returns an error. In v2 (unknwon.dev/ini/v2) as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions