Open
Conversation
This prevents SIGSEGVs when accessing the argument's options.
This issue was discovered due to a SIGSEGV when trying to print the help
message of argument with no options.
Minimal reproduction program:
----------
package main
import (
"os"
"github.com/akamensky/argparse"
)
func main() {
p := argparse.NewParser("noopts", "")
_ = p.String("s", "string", nil)
_ = p.Parse(os.Args)
}
----------
$ go run noopts.go -h
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x49e5a3]
goroutine 1 [running]:
github.com/akamensky/argparse.(*Command).precedingCommands2Result(0xc000114000, {0x4ca231, 0x6}, {0xc00001e200, 0x1, 0x4c0c60?}, {0xc00001e210, 0x2, 0x474647?}, 0x50)
/some_path/argparse/argparse.go:619 +0x163
github.com/akamensky/argparse.(*Command).Usage(0xc000114000, {0x0?, 0x0?})
/some_path/argparse/argparse.go:753 +0x4bf
github.com/akamensky/argparse.(*Command).Help(0x49c6c5?, {0x0?, 0x0?})
/some_path/argparse/argparse.go:75 +0x47
github.com/akamensky/argparse.(*arg).parseSomeType(0xc00002a080, {0xc0000120b0?, 0x5a31c0?, 0x400000?}, 0xc000104c18?)
/some_path/argparse/argument.go:395 +0x85
github.com/akamensky/argparse.(*arg).parse(0x7ffc543f5cf3?, {0xc0000120b0?, 0x4c9f7f?, 0x10?}, 0x5839c0?)
/some_path/argparse/argument.go:445 +0x371
github.com/akamensky/argparse.(*Command).parseArguments(0x1?, 0xc000104ed0)
/some_path/argparse/command.go:170 +0x405
github.com/akamensky/argparse.(*Command).parse(0xc000114000, 0xc000104ed0)
/some_path/argparse/command.go:231 +0x10b
github.com/akamensky/argparse.(*Parser).Parse(0xc000114000, {0xc000012080?, 0x2, 0x4ca22b?})
/some_path/argparse/argparse.go:772 +0x76
main.main()
/some_path/argparse/examples/noopts.go:12 +0x6b
exit status 2
akamensky
reviewed
Jan 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This prevents SIGSEGVs when accessing the argument's options.
This issue was discovered due to a SIGSEGV when trying to print the help message of argument with no options.
Minimal reproduction program: