From 06f138a6893c083e52eb82dbf5122c19dad0283f Mon Sep 17 00:00:00 2001
From: "xialong.lee"
Date: Wed, 9 Nov 2016 13:58:31 +0800
Subject: [PATCH] mention overflows when mistakenly call function FromInt
---
pkg/util/intstr/BUILD | 1 +
pkg/util/intstr/intstr.go | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/pkg/util/intstr/BUILD b/pkg/util/intstr/BUILD
index 600ecb08e33..0d31a74cca3 100644
--- a/pkg/util/intstr/BUILD
+++ b/pkg/util/intstr/BUILD
@@ -21,6 +21,7 @@ go_library(
"//pkg/genericapiserver/openapi/common:go_default_library",
"//vendor:github.com/go-openapi/spec",
"//vendor:github.com/gogo/protobuf/proto",
+ "//vendor:github.com/golang/glog",
"//vendor:github.com/google/gofuzz",
],
)
diff --git a/pkg/util/intstr/intstr.go b/pkg/util/intstr/intstr.go
index 248a16cc431..48f798ae505 100644
--- a/pkg/util/intstr/intstr.go
+++ b/pkg/util/intstr/intstr.go
@@ -20,12 +20,14 @@ import (
"encoding/json"
"fmt"
"math"
+ "runtime/debug"
"strconv"
"strings"
"k8s.io/kubernetes/pkg/genericapiserver/openapi/common"
"github.com/go-openapi/spec"
+ "github.com/golang/glog"
"github.com/google/gofuzz"
)
@@ -57,6 +59,9 @@ const (
// than int32.
// TODO: convert to (val int32)
func FromInt(val int) IntOrString {
+ if val > math.MaxInt32 || val < math.MinInt32 {
+ glog.Errorf("value: %d overflows int32\n%s\n", val, debug.Stack())
+ }
return IntOrString{Type: Int, IntVal: int32(val)}
}