mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
tsdb: Avoid potential overflow in comparisons
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
26d07ee8d3
commit
02680b42f6
|
@ -63,6 +63,15 @@ func (m *maxHeap) push(item Stat) {
|
|||
}
|
||||
|
||||
func (m *maxHeap) get() []Stat {
|
||||
slices.SortFunc(m.Items, func(a, b Stat) int { return int(b.Count - a.Count) })
|
||||
slices.SortFunc(m.Items, func(a, b Stat) int {
|
||||
switch {
|
||||
case b.Count < a.Count:
|
||||
return -1
|
||||
case b.Count > a.Count:
|
||||
return 1
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
})
|
||||
return m.Items
|
||||
}
|
||||
|
|
|
@ -184,17 +184,39 @@ type chunkMetaAndChunkDiskMapperRef struct {
|
|||
}
|
||||
|
||||
func refLessByMinTimeAndMinRef(a, b chunkMetaAndChunkDiskMapperRef) int {
|
||||
if a.meta.MinTime == b.meta.MinTime {
|
||||
return int(a.meta.Ref - b.meta.Ref)
|
||||
switch {
|
||||
case a.meta.MinTime < b.meta.MinTime:
|
||||
return -1
|
||||
case a.meta.MinTime > b.meta.MinTime:
|
||||
return 1
|
||||
}
|
||||
|
||||
switch {
|
||||
case a.meta.Ref < b.meta.Ref:
|
||||
return -1
|
||||
case a.meta.Ref > b.meta.Ref:
|
||||
return 1
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
return int(a.meta.MinTime - b.meta.MinTime)
|
||||
}
|
||||
|
||||
func lessByMinTimeAndMinRef(a, b chunks.Meta) int {
|
||||
if a.MinTime == b.MinTime {
|
||||
return int(a.Ref - b.Ref)
|
||||
switch {
|
||||
case a.MinTime < b.MinTime:
|
||||
return -1
|
||||
case a.MinTime > b.MinTime:
|
||||
return 1
|
||||
}
|
||||
|
||||
switch {
|
||||
case a.Ref < b.Ref:
|
||||
return -1
|
||||
case a.Ref > b.Ref:
|
||||
return 1
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
return int(a.MinTime - b.MinTime)
|
||||
}
|
||||
|
||||
func (oh *OOOHeadIndexReader) Postings(ctx context.Context, name string, values ...string) (index.Postings, error) {
|
||||
|
|
Loading…
Reference in a new issue