Skip to content

Panic while word-diffing #56

@mdruiter

Description

@mdruiter

I get an exception, while comparing two simple files using csvdiff -o word-diff:

x,[-C-]{+A+}
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/aswinkarthik/csvdiff/cmd.(*Formatter).wordLevelDiffs(0xc0000f7ac0, 0xb1a638, 0x0, 0x0, 0xc000182000, 0x2, 0x2, 0xb1a638, 0x0, 0x0, ...)
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/cmd/formatter.go:242 +0x1338
github.com/aswinkarthik/csvdiff/cmd.(*Formatter).wordDiff(...)
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/cmd/formatter.go:216
github.com/aswinkarthik/csvdiff/cmd.(*Formatter).Format(0xc0000f7ac0, 0xb1a638, 0x0, 0x0, 0xc000182000, 0x2, 0x2, 0xb1a638, 0x0, 0x0, ...)
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/cmd/formatter.go:51 +0x504
github.com/aswinkarthik/csvdiff/cmd.runContext(0xc0000f0000, 0x884060, 0xc000010018, 0x884060, 0xc000010020, 0x0, 0x0)
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/cmd/root.go:108 +0x4c5
github.com/aswinkarthik/csvdiff/cmd.glob..func2(0xaf89c0, 0xc0000243c0, 0x2, 0x4, 0x0, 0x0)
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/cmd/root.go:87 +0x283
github.com/spf13/cobra.(*Command).execute(0xaf89c0, 0xc000012060, 0x4, 0x4, 0xaf89c0, 0xc000012060)
        /home/travis/gopath/pkg/mod/github.com/spf13/[email protected]/command.go:826 +0x460
github.com/spf13/cobra.(*Command).ExecuteC(0xaf89c0, 0xc00005cda0, 0xc000059f20, 0x43cb8a)
        /home/travis/gopath/pkg/mod/github.com/spf13/[email protected]/command.go:914 +0x2fb
github.com/spf13/cobra.(*Command).Execute(...)
        /home/travis/gopath/pkg/mod/github.com/spf13/[email protected]/command.go:864
github.com/aswinkarthik/csvdiff/cmd.Execute()
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/cmd/root.go:115 +0x76
main.main()
        /home/travis/gopath/src/github.com/aswinkarthik/csvdiff/main.go:29 +0x59

Interestingly enough, this even happens with two equal files, including the difference found ([-C-]{+A+}).
My example data, for both files:

x,A
x,B
x,C

I tested both DOS (CRLF) and UNIX (LF) line endings. I'm running version 1.4.0 in Ubuntu via WSL2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions