labels: make sure estimated size is not negative
Deleted labels are remembered, even if they were not in `base` or were removed from `add`, so `base+add-del` could go negative. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
b987afa7ef
commit
e917202766
|
@ -577,7 +577,11 @@ func (b *Builder) Labels() Labels {
|
||||||
return b.base
|
return b.base
|
||||||
}
|
}
|
||||||
|
|
||||||
res := make(Labels, 0, len(b.base)-len(b.del)+len(b.add))
|
expectedSize := len(b.base) + len(b.add) - len(b.del)
|
||||||
|
if expectedSize < 1 {
|
||||||
|
expectedSize = 1
|
||||||
|
}
|
||||||
|
res := make(Labels, 0, expectedSize)
|
||||||
for _, l := range b.base {
|
for _, l := range b.base {
|
||||||
if slices.Contains(b.del, l.Name) || contains(b.add, l.Name) {
|
if slices.Contains(b.del, l.Name) || contains(b.add, l.Name) {
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue