Browse Source

codec: growCap: accomodate 32-bit OS

Ugorji Nwoke 6 years ago
parent
commit
bed8f2ebe4
1 changed files with 4 additions and 1 deletions
  1. 4 1
      codec/helper_internal.go

+ 4 - 1
codec/helper_internal.go

@@ -75,7 +75,10 @@ func growCap(oldCap, unit, num int) (newCap int) {
 
 	// unit can be 0 e.g. for struct{}{}; handle that appropriately
 	if unit <= 0 {
-		return 1<<63 - 1 // math.MaxInt64
+		if uint64(^uint(0)) == ^uint64(0) { // 64-bit
+			return int(1<<63 - 1) // math.MaxInt64
+		}
+		return int(1<<31 - 1) //  math.MaxInt32
 	}
 
 	// handle if num < 0, cap=0, etc.