From f1fae83548ce0053d551128c7a5a4609255d0a28 Mon Sep 17 00:00:00 2001 From: Chord Date: Thu, 19 May 2016 01:55:43 -0400 Subject: [PATCH] Fixed enumeration bounds check bug --- common/src/main/scala/net/psforever/packet/PSPacket.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/src/main/scala/net/psforever/packet/PSPacket.scala b/common/src/main/scala/net/psforever/packet/PSPacket.scala index cb3c4fb4..d2328b9d 100644 --- a/common/src/main/scala/net/psforever/packet/PSPacket.scala +++ b/common/src/main/scala/net/psforever/packet/PSPacket.scala @@ -80,10 +80,11 @@ object PacketHelpers { def createEnumerationCodec[E <: Enumeration](enum : E, storageCodec : Codec[Int]) : Codec[E#Value] = { type Struct = Int :: HNil val struct: Codec[Struct] = storageCodec.hlist + val primitiveLimit = Math.pow(2, storageCodec.sizeBound.exact.get) // Assure that the enum will always be able to fit in a N-bit int - assert(enum.maxId <= Math.pow(storageCodec.sizeBound.exact.get, 2), - enum.getClass.getCanonicalName + ": maxId exceeds primitive type") + assert(enum.maxId <= primitiveLimit, + enum.getClass.getCanonicalName + s": maxId exceeds primitive type (limit of $primitiveLimit, maxId ${enum.maxId})") def to(pkt: E#Value): Struct = { pkt.id :: HNil