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 {
|
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
|
return m.Items
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,17 +184,39 @@ type chunkMetaAndChunkDiskMapperRef struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func refLessByMinTimeAndMinRef(a, b chunkMetaAndChunkDiskMapperRef) int {
|
func refLessByMinTimeAndMinRef(a, b chunkMetaAndChunkDiskMapperRef) int {
|
||||||
if a.meta.MinTime == b.meta.MinTime {
|
switch {
|
||||||
return int(a.meta.Ref - b.meta.Ref)
|
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 {
|
func lessByMinTimeAndMinRef(a, b chunks.Meta) int {
|
||||||
if a.MinTime == b.MinTime {
|
switch {
|
||||||
return int(a.Ref - b.Ref)
|
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) {
|
func (oh *OOOHeadIndexReader) Postings(ctx context.Context, name string, values ...string) (index.Postings, error) {
|
||||||
|
|
Loading…
Reference in a new issue