Skip to content

Commit 4da6e5a

Browse files
authored
avoiding overflow warning for 32/64 bit system (#370)
# Description Building for 32-bit is giving this error: `cannot use roomIdMin64 (untyped int constant 1000000000000) as int value in assignment (overflows)` Even though there is runtime detection for the integer bitsize, we still need to trick the compiler. This sets it to the 32 bit value and then multiplies it by 1000 if the maxint is over this number. ## Changes - Changed the way we check for which minimum ephemeral RoomId value to use.
1 parent 62fd1f5 commit 4da6e5a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

internal/rooms/ephemeral.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@ import (
55
"fmt"
66
"math"
77
"time"
8-
"unsafe"
98

109
"github.com/GoMudEngine/GoMud/internal/mudlog"
1110
"github.com/GoMudEngine/GoMud/internal/util"
1211
)
1312

1413
const (
15-
ephemeralChunksLimit = 100 // The maximum number of ephemeral chunks that can be created
16-
ephemeralChunkSize = 250 // The maximum quantity of ephemeral room's that can be copied/created in a given chunk.
17-
roomIdMin32 = 1000000000 // 1,000,000,000
18-
roomIdMin64 = 1000000000000 // 1,000,000,000,000
14+
ephemeralChunksLimit = 100 // The maximum number of ephemeral chunks that can be created
15+
ephemeralChunkSize = 250 // The maximum quantity of ephemeral room's that can be copied/created in a given chunk.
16+
roomIdMin32Bit = 1000000000 // 1,000,000,000
1917
)
2018

2119
var (
22-
ephemeralRoomIdMinimum = roomIdMin32 // 1,000,000,000 is assuming 32 bit. the init() function may override this value.
20+
ephemeralRoomIdMinimum = roomIdMin32Bit // 1,000,000,000 is assuming 32 bit. the init() function may override this value.
2321
ephemeralRoomChunks = [ephemeralChunksLimit][]int{} // map of ranges to actual rooms. If empty, slot is available.
2422
originalRoomIdLookups = map[int]int{} // a map of ephemeralId's to their original RoomId's, for special purposes
2523
// errors
@@ -224,9 +222,7 @@ func GetOriginalRoom(roomId int) int {
224222
}
225223

226224
func init() {
227-
if unsafe.Sizeof(int(0))*8 == 64 {
228-
ephemeralRoomIdMinimum = roomIdMin64
229-
} else {
230-
ephemeralRoomIdMinimum = roomIdMin32
225+
if math.MaxInt > ephemeralRoomIdMinimum*1000 {
226+
ephemeralRoomIdMinimum = ephemeralRoomIdMinimum * 1000 // 1,000,000,000 => // 1,000,000,000,000
231227
}
232228
}

0 commit comments

Comments
 (0)