string
to int
signedness casting GO-E1006 503 } else if oldKG.IsMerging() {
504 return ErrKeyspaceGroupInMerging(uint32(oldID))
505 } else if newKG.IsMerging() {
506 return ErrKeyspaceGroupInMerging(uint32(newID)) 507 }
508
509 var updateOld, updateNew bool
501 } else if newKG.IsSplitting() {
502 return ErrKeyspaceGroupInSplit(uint32(newID))
503 } else if oldKG.IsMerging() {
504 return ErrKeyspaceGroupInMerging(uint32(oldID)) 505 } else if newKG.IsMerging() {
506 return ErrKeyspaceGroupInMerging(uint32(newID))
507 }
492 if oldKG == nil {
493 return errors.Errorf("keyspace group %s not found in %s group", oldGroupID, oldUserKind)
494 }
495 newKG := m.groups[newUserKind].Get(uint32(newID)) 496 if newKG == nil {
497 return errors.Errorf("keyspace group %s not found in %s group", newGroupID, newUserKind)
498 }
488
489 m.Lock()
490 defer m.Unlock()
491 oldKG := m.groups[oldUserKind].Get(uint32(oldID)) 492 if oldKG == nil {
493 return errors.Errorf("keyspace group %s not found in %s group", oldGroupID, oldUserKind)
494 }
499 if oldKG.IsSplitting() {
500 return ErrKeyspaceGroupInSplit(uint32(oldID))
501 } else if newKG.IsSplitting() {
502 return ErrKeyspaceGroupInSplit(uint32(newID)) 503 } else if oldKG.IsMerging() {
504 return ErrKeyspaceGroupInMerging(uint32(oldID))
505 } else if newKG.IsMerging() {
It is possible for integer casting, if not appropriately done to lose the signedness of the integer and might cause overflow as well.
For example:
- int64
must not be casted to: "uint8", "uint16", "uint32", "uint64", "int8", "int16", "int32"
int64
can lose signedness if converted to unsigned integer and if converted to
a signed integer but a type other than int64
, then overflow might occur.
uint64
must not be casted to: "uint8", "uint16", "uint32", "int8", "int16", "int32", "int64"
uint64
would lose signedness if converted to a signed integer and might overflow.
If converted to an unsigned integer, i.e., a type other than uint64
, overflow
might occur.n, err := strconv.Atoi("42")
if err != nil {
panic(err)
}
// `n` is of type `int`, so it is either `int64` or `int32` depending on the platform.
// Casting it to `uint8` might result in loss of signedness of the integer and might
// not give expected results.
_ = uint8(n)