emersion / go-webdav

A Go library for WebDAV, CalDAV and CardDAV
MIT License
314 stars 66 forks source link

internal: fix always-true interface comparison #135

Closed sbinet closed 8 months ago

sbinet commented 8 months ago

This CL corrects the following bug uncovered by staticcheck:

  internal/elements.go:148:6: this comparison is always true (SA4023)
    internal/elements.go:146:18: the lhs of the comparison gets its value from here and has a concrete type
emersion commented 8 months ago

Ouch. That's the usual "nil pointer but not actually nil interface" footgun right?

Can we ensure that we never return a nil *Error (which ends up being a non-nil error)? Even if resp.ResponseDescription == ""?

Probably this would help:

var err error
if resp.Error != nil {
    err = resp.Error
}
sbinet commented 8 months ago

That's the usual "nil pointer but not actually nil interface" footgun right?

yep, that's the one.

PTAL.