diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 4da9a8727..1e2859ba7 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -275,8 +275,14 @@ const Type* GetStructReplacementType (const Type* SType) long GetIntegerTypeMin (const Type* Type) -/* Get the smallest possible value of the integer type */ +/* Get the smallest possible value of the integer type. +** The type must have a known size. +*/ { + if (SizeOf (Type) == 0) { + Internal ("Incomplete type used in GetIntegerTypeMin"); + } + if (IsSignSigned (Type)) { /* The smallest possible signed value of N-byte integer is -pow(2, 8*N-1) */ return (long)((unsigned long)(-1L) << (CHAR_BITS * SizeOf (Type) - 1U)); @@ -288,8 +294,14 @@ long GetIntegerTypeMin (const Type* Type) unsigned long GetIntegerTypeMax (const Type* Type) -/* Get the largest possible value of the integer type */ +/* Get the largest possible value of the integer type. +** The type must have a known size. +*/ { + if (SizeOf (Type) == 0) { + Internal ("Incomplete type used in GetIntegerTypeMax"); + } + if (IsSignSigned (Type)) { /* Min signed value of N-byte integer is pow(2, 8*N-1) - 1 */ return (1UL << (CHAR_BITS * SizeOf (Type) - 1U)) - 1UL; diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index 361f5e0a6..2f2ed136e 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -249,10 +249,14 @@ const Type* GetStructReplacementType (const Type* SType); /* Get a replacement type for passing a struct/union in the primary register */ long GetIntegerTypeMin (const Type* Type); -/* Get the smallest possible value of the integer type */ +/* Get the smallest possible value of the integer type. +** The type must have a known size. +*/ unsigned long GetIntegerTypeMax (const Type* Type); -/* Get the largest possible value of the integer type */ +/* Get the largest possible value of the integer type. +** The type must have a known size. +*/ Type* PointerTo (const Type* T); /* Return a type string that is "pointer to T". The type string is allocated