Skip to content

Commit 127074e

Browse files
committed
runner: keep input counters incrementing under -skip-dedupe
Revert the defensive strconv.Atoi guard around the SkipDedupe branches: values stored in r.hm are always integer strings written by this same code path, so the parseErr/cnt>0 check is unreachable in practice, and when taken literally it skipped the numHosts/numTargets increment for duplicate inputs.
1 parent 5ccf827 commit 127074e

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

runner/runner.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,9 @@ func (r *Runner) prepareInput() {
552552
r.hm.Set(target, []byte("1")) //nolint
553553
} else if r.options.SkipDedupe && errors.Is(err, duplicateTargetErr) {
554554
if v, ok := r.hm.Get(target); ok {
555-
if cnt, parseErr := strconv.Atoi(string(v)); parseErr == nil && cnt > 0 {
556-
_ = r.hm.Set(target, []byte(strconv.Itoa(cnt+1)))
557-
numHosts += 1
558-
}
555+
cnt, _ := strconv.Atoi(string(v))
556+
_ = r.hm.Set(target, []byte(strconv.Itoa(cnt+1)))
557+
numHosts += 1
559558
}
560559
}
561560
}
@@ -800,10 +799,9 @@ func (r *Runner) loadAndCloseFile(finput *os.File) (numTargets int, err error) {
800799
r.hm.Set(target, []byte("1")) //nolint
801800
} else if r.options.SkipDedupe && errors.Is(err, duplicateTargetErr) {
802801
if v, ok := r.hm.Get(target); ok {
803-
if cnt, parseErr := strconv.Atoi(string(v)); parseErr == nil && cnt > 0 {
804-
_ = r.hm.Set(target, []byte(strconv.Itoa(cnt+1)))
805-
numTargets += 1
806-
}
802+
cnt, _ := strconv.Atoi(string(v))
803+
_ = r.hm.Set(target, []byte(strconv.Itoa(cnt+1)))
804+
numTargets += 1
807805
}
808806
}
809807
}
@@ -826,10 +824,9 @@ func (r *Runner) loadFromFormat(filePath string, format inputformats.Format) (nu
826824
r.hm.Set(target, []byte("1")) //nolint
827825
} else if r.options.SkipDedupe && errors.Is(countErr, duplicateTargetErr) {
828826
if v, ok := r.hm.Get(target); ok {
829-
if cnt, parseErr := strconv.Atoi(string(v)); parseErr == nil && cnt > 0 {
830-
_ = r.hm.Set(target, []byte(strconv.Itoa(cnt+1)))
831-
numTargets += 1
832-
}
827+
cnt, _ := strconv.Atoi(string(v))
828+
_ = r.hm.Set(target, []byte(strconv.Itoa(cnt+1)))
829+
numTargets += 1
833830
}
834831
}
835832
return true

0 commit comments

Comments
 (0)