summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-01-12 14:18:00 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-01-24 08:18:50 +0900
commit549b7037381ec51d0c5b9a0abbe8f73000fda70c (patch)
tree40ed8a74f1b75990071b79e363e331887e7db51e /table
parentb391322bcbf56d623ca0a6b667c026b92f1e9e4d (diff)
*: Use strconv.ParseUint instead of strconv.Atoi()
For the 32-bit platform compatibility. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'table')
-rw-r--r--table/policy.go16
-rw-r--r--table/policy_test.go11
2 files changed, 14 insertions, 13 deletions
diff --git a/table/policy.go b/table/policy.go
index e1b7d690..a7d02b06 100644
--- a/table/policy.go
+++ b/table/policy.go
@@ -337,8 +337,8 @@ func NewPrefix(c config.Prefix) (*Prefix, error) {
return nil, fmt.Errorf("mask length range format is invalid")
}
// we've already checked the range is sane by regexp
- min, _ := strconv.Atoi(elems[1])
- max, _ := strconv.Atoi(elems[2])
+ min, _ := strconv.ParseUint(elems[1], 10, 8)
+ max, _ := strconv.ParseUint(elems[2], 10, 8)
p.MasklengthRangeMin = uint8(min)
p.MasklengthRangeMax = uint8(max)
}
@@ -716,25 +716,25 @@ func NewSingleAsPathMatch(arg string) *singleAsPathMatch {
onlyRe := regexp.MustCompile("^\\^([0-9]+)\\$$")
switch {
case leftMostRe.MatchString(arg):
- asn, _ := strconv.Atoi(leftMostRe.FindStringSubmatch(arg)[1])
+ asn, _ := strconv.ParseUint(leftMostRe.FindStringSubmatch(arg)[1], 10, 32)
return &singleAsPathMatch{
asn: uint32(asn),
mode: LEFT_MOST,
}
case originRe.MatchString(arg):
- asn, _ := strconv.Atoi(originRe.FindStringSubmatch(arg)[1])
+ asn, _ := strconv.ParseUint(originRe.FindStringSubmatch(arg)[1], 10, 32)
return &singleAsPathMatch{
asn: uint32(asn),
mode: ORIGIN,
}
case includeRe.MatchString(arg):
- asn, _ := strconv.Atoi(includeRe.FindStringSubmatch(arg)[1])
+ asn, _ := strconv.ParseUint(includeRe.FindStringSubmatch(arg)[1], 10, 32)
return &singleAsPathMatch{
asn: uint32(asn),
mode: INCLUDE,
}
case onlyRe.MatchString(arg):
- asn, _ := strconv.Atoi(onlyRe.FindStringSubmatch(arg)[1])
+ asn, _ := strconv.ParseUint(onlyRe.FindStringSubmatch(arg)[1], 10, 32)
return &singleAsPathMatch{
asn: uint32(asn),
mode: ONLY,
@@ -985,8 +985,8 @@ func ParseCommunity(arg string) (uint32, error) {
exp := regexp.MustCompile("(\\d+):(\\d+)")
elems := exp.FindStringSubmatch(arg)
if len(elems) == 3 {
- fst, _ := strconv.Atoi(elems[1])
- snd, _ := strconv.Atoi(elems[2])
+ fst, _ := strconv.ParseUint(elems[1], 10, 16)
+ snd, _ := strconv.ParseUint(elems[2], 10, 16)
return uint32(fst<<16 | snd), nil
}
for i, v := range bgp.WellKnownCommunityNameMap {
diff --git a/table/policy_test.go b/table/policy_test.go
index c55eb1c8..cf02b095 100644
--- a/table/policy_test.go
+++ b/table/policy_test.go
@@ -24,10 +24,11 @@ import (
"testing"
"time"
- "github.com/osrg/gobgp/config"
- "github.com/osrg/gobgp/packet/bgp"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
+
+ "github.com/osrg/gobgp/config"
+ "github.com/osrg/gobgp/packet/bgp"
)
func TestPrefixCalcurateNoRange(t *testing.T) {
@@ -2800,9 +2801,9 @@ func createNeighborSet(name string, addr string) config.NeighborSet {
func createAs4Value(s string) uint32 {
v := strings.Split(s, ".")
- upper, _ := strconv.Atoi(v[0])
- lower, _ := strconv.Atoi(v[1])
- return uint32(upper)<<16 + uint32(lower)
+ upper, _ := strconv.ParseUint(v[0], 10, 16)
+ lower, _ := strconv.ParseUint(v[1], 10, 16)
+ return uint32(upper<<16 | lower)
}
func TestPrefixSetOperation(t *testing.T) {