Check if the integer size is known in GetIntegerTypeMin/Max() to prevent potential misuse.
This commit is contained in:
@@ -275,8 +275,14 @@ const Type* GetStructReplacementType (const Type* SType)
|
|||||||
|
|
||||||
|
|
||||||
long GetIntegerTypeMin (const Type* Type)
|
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)) {
|
if (IsSignSigned (Type)) {
|
||||||
/* The smallest possible signed value of N-byte integer is -pow(2, 8*N-1) */
|
/* 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));
|
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)
|
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)) {
|
if (IsSignSigned (Type)) {
|
||||||
/* Min signed value of N-byte integer is pow(2, 8*N-1) - 1 */
|
/* Min signed value of N-byte integer is pow(2, 8*N-1) - 1 */
|
||||||
return (1UL << (CHAR_BITS * SizeOf (Type) - 1U)) - 1UL;
|
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 */
|
/* Get a replacement type for passing a struct/union in the primary register */
|
||||||
|
|
||||||
long GetIntegerTypeMin (const Type* Type);
|
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);
|
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);
|
Type* PointerTo (const Type* T);
|
||||||
/* Return a type string that is "pointer to T". The type string is allocated
|
/* Return a type string that is "pointer to T". The type string is allocated
|
||||||
|
|||||||
Reference in New Issue
Block a user