The analyzer found a possible error related to the implicit conversion of the return value. The error consists in dropping of the high bits in the 64-bit type which causes the loss of value.
Let’s examine an example.
Copy Code | |
|---|---|
| |
The result of the end - begin expression has type ptrdiff_t. But as the function returns type unsigned the implicit type conversion occurs which causes the loss of the result high bits. Thus, if the pointers begin and end refer to the beginning and the end of the array according to a larger UINT_MAX (4Gb), the function will return the incorrect value.
The correction consists in modifying the program in such a way so that the arrays sizes are kept and transported in memsize types. In this case the correct code of the GetSize function should look as follows:
Copy Code | |
|---|---|
| |
When you are sure that the code is correct and the implicit type conversion does not cause errors while porting to the 64-bit architecture you may use the explicit type conversion so that to avoid showing of the warning messages. For example:
Copy Code | |
|---|---|
| |
If you suspect that the code contains incorrect explicit conversions of the return values types about which the analyzer does not warn you may use the Find incorrect explicit type conversion mode.
See also: