mirror of
https://github.com/cc65/cc65.git
synced 2025-01-05 15:30:44 +00:00
Check if the integer size is known in GetIntegerTypeMin/Max() to prevent potential misuse.
This commit is contained in:
parent
0f412b6beb
commit
c37f9f1a41
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user