10 examples of 'signed integer overflow' in Go

Every line of 'signed integer overflow' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
704func OpSHR_uint64_uint32(x uint64, y uint32) uint64 {
705 return x >> y
706}
428func overflowErr(v reflect.Value, x interface{}) error {
429 return fmt.Errorf("firestore: value %v overflows type %s", x, v.Type())
430}
1532func (v Value) OverflowInt(x int64) bool {
1533 k := v.kind()
1534 switch k {
1535 case Int, Int8, Int16, Int32, Int64:
1536 bitSize := v.typ.size * 8
1537 trunc := (x << (64 - bitSize)) >> (64 - bitSize)
1538 return x != trunc
1539 }
1540 panic(&ValueError{"reflect.Value.OverflowInt", v.kind()})
1541}
304func divzerouint32(x, y uint32) uint32 {
305 defer checkudivzero("uint32", uint64(x))
306 return x / y
307}
141func eth_check_overflow_uint32(a[]byte)bool{
142 var yes bool
143 var no bool
144 yes=false
145 no=false
146 curveOrder := GetCurveOrder(ECC_CURVE_SECP256K1)
147 a_uint32:=eth_set_uint32(a)
148 curveOrder_uint32:=eth_set_uint32(curveOrder)
149 no=no||(a_uint32[0] < curveOrder_uint32[0])/*no need check for a > check.*/
150 no=no||(a_uint32[1]curveOrder_uint32[3])&&(!no)
151 no=no||(a_uint32[4]curveOrder_uint32[4])&&(!no)
152 no=no||(a_uint32[5]curveOrder_uint32[5])&&(!no)
153 no=no||(a_uint32[6]curveOrder_uint32[6])&&(!no)
154 yes=yes||(a_uint32[7]>=curveOrder_uint32[7])&&(!no)
155
156 return yes
157}
616func OpSHR_uint_uint8(x uint, y uint8) uint {
617 return x >> y
618}
1542func SubOverflowInt64(a, b int64) (r int64, ovf bool) {
1543 r = a - b
1544 if a >= 0 && b < 0 {
1545 return r, uint64(r) >= math.MaxInt64+1
1546 }
1547
1548 if a < 0 && b > 0 {
1549 return r, uint64(r) <= math.MaxInt64
1550 }
1551
1552 return r, false
1553}
2338func (checkOverflow) Uint(v uint64, bitsize uint8) (overflow bool) {
2339 if v != 0 && v != (v<<(64-bitsize))>>(64-bitsize) {
2340 overflow = true
2341 }
2342 return
2343}
72func BigInt2Uint64Le(z []uint64, x *big.Int) {
73 xLen := (x.BitLen() + 63) >> 6 // number of 64-bit words
74 zLen := len(z)
75 if zLen >= xLen && x.Sign() > 0 {
76 var y, yi big.Int
77 y.Set(x)
78 two64 := big.NewInt(1)
79 two64.Lsh(two64, 64).Sub(two64, big.NewInt(1))
80 for i := 0; i < xLen; i++ {
81 yi.And(&y, two64)
82 z[i] = yi.Uint64()
83 y.Rsh(&y, 64)
84 }
85 }
86 for i := xLen; i < zLen; i++ {
87 z[i] = 0
88 }
89}
75func addUint64Overflow(a, b uint64) (uint64, bool) {
76 if math.MaxUint64-a < b {
77 return 0, true
78 }
79
80 return a + b, false
81}

Related snippets