diff --git a/inotify.go b/inotify.go index 6a5d74d..55ad01f 100644 --- a/inotify.go +++ b/inotify.go @@ -461,7 +461,7 @@ func (i *Inotify) ReadDeadline(deadline time.Time) ([]InotifyEvent, error) { } func ValidateVsMaximumAllowedUint32Size(wd int) error { - if wd > 0 && wd > MaxUint32 { + if wd < 0 || wd > MaxUint32 { return WatchesNumberUint32OverflowError } return nil diff --git a/inotify_test.go b/inotify_test.go index f83db36..49eca27 100644 --- a/inotify_test.go +++ b/inotify_test.go @@ -340,6 +340,13 @@ func TestValidateInteger(t *testing.T) { } }) + t.Run("Negative", func(t *testing.T) { + verr := ValidateVsMaximumAllowedUint32Size(-1) + if !errors.Is(verr, WatchesNumberUint32OverflowError) { + t.Error(verr) + } + }) + t.Run("Ok", func(t *testing.T) { verr := ValidateVsMaximumAllowedUint32Size(22949) if errors.Is(verr, WatchesNumberUint32OverflowError) {