1

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 :)

0

2 Answers 2

2

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?

Sign up to request clarification or add additional context in comments.

1 Comment

You are right, this is an embedded system and uses a 16bit int. So it is likely the cast is affected by it :). I have to double check but my guess is you are correct.
1

There are 2 potential issues:

The error might be in the line above:

luw_BlockPointer = ( READ_EEP_32(lpul_BATEntry) & 0xFFFFuL );
sizeof(0xFFFFuL) == 8 and sizeof(luw_BlockPointer) == 2

Try to take the T_ULONG cast off as it should allow you to add an unsigned short to an unsigned long without a cast:

return (T_EEP_ADDRESS)((0x00E9800UL)+ luw_BlockPointer );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.