I'm working with a code analysis tool called Polyspace. I got a "possible overflow" notification on one code section and just can figure it out :)
Error : operation [conversion from unsigned int32 to unsigned int16] on scalar overflows (results is always strictly greater than MAX UINT16) conversion from unsigned int 32 to unsigned int 16 right: [956448 .. 972799]
The code is:
typedef unsigned char T_UBYTE;
typedef unsigned short int T_UWORD;
typedef unsigned long int T_ULONG;
typedef void __far * T_EEP_ADDRESS;
..
T_EEP_ADDRESS beeeblock_GetBlockPointer(T_UWORD luw_BATAddress)
{
T_UWORD luw_BlockPointer;
T_EEP_ADDRESS lpul_BATEntry;
..
luw_BlockPointer = ( READ_EEP_32(lpul_BATEntry) & 0xFFFFuL );
..
return (T_EEP_ADDRESS)((0x00E9800UL)+ (T_ULONG)luw_BlockPointer );
}
The line causing the error is this:
return (T_EEP_ADDRESS)((0x00E9800UL)+ (T_ULONG)luw_BlockPointer );
Any help would be extremely welcome :)
It looks like the type
T_EEP_ADDRESS
is 16 bit, and((0x00E9800UL)+ (T_ULONG)luw_BlockPointer )
is a 32 bit-result, so you're converting a large number into a smaller one and loosing information.What system is this on? Do you know the pointer size, since
T_EEP_ADDRESS
is a pointer?