prevent int64 overflow when reading the expiry date of the server config

This commit is contained in:
Marten Seemann
2016-11-16 12:42:19 +07:00
parent f9013edb77
commit 52ba2ce9f8
4 changed files with 26 additions and 1 deletions

View File

@@ -34,6 +34,14 @@ func MaxUint64(a, b uint64) uint64 {
return a
}
// MinUint64 returns the maximum of two uint64
func MinUint64(a, b uint64) uint64 {
if a < b {
return a
}
return b
}
// Min returns the minimum of two Ints
func Min(a, b int) int {
if a < b {

View File

@@ -25,6 +25,11 @@ var _ = Describe("Min / Max", func() {
Expect(MaxUint64(7, 5)).To(Equal(uint64(7)))
})
It("returns the minimum uint64", func() {
Expect(MinUint64(5, 7)).To(Equal(uint64(5)))
Expect(MinUint64(7, 5)).To(Equal(uint64(5)))
})
It("returns the maximum int64", func() {
Expect(MaxInt64(5, 7)).To(Equal(int64(7)))
Expect(MaxInt64(7, 5)).To(Equal(int64(7)))