[Zlib-devel] zlib: Run-Time Check Failure #1 - A cast tosmaller data type

Glenn Randers-Pehrson glennrp at comcast.net
Mon Aug 27 11:53:00 EDT 2007


At 08:11 AM 8/27/2007 -0700, Mark Adler wrote:
>On Aug 27, 2007, at 5:09 AM, Glenn Randers-Pehrson wrote:
>> Visual Studio say: Run-Time Check Failure #1 - A cast to smaller  
>> data type
>> has caused a loss of data. If this was intentional, you should mask  
>> the
>> source of the cast with the appropriate bitmask. For example: char  
>> c = (i &
>> 0xFF); Changing the code in this way will not affect the quality of  
>> the
>> resulting optimized code.
>
>Glenn,
>
>Thank you for the report.
>
>Does Visual Studio have to be asked to produce this "check failure"?   
>I'm wondering if this should be fixed, since it's not obvious that  
>all compilers will optimize out the & 0xff.  I believe that there are  
>many other places in zlib where the & 0xff is implicit in the  
>assignment to a char.

I think doing ... (char)integer
is equivalent to   integer & 0xff

but simply using an integer as a char, which I guess is what's happening
here, will trigger the warning.

i.e., the fix is "send_code (s, (unsigned char)lc, ltree);"

If there are many other similar instances, then they should all be
fixed if we want to be pedantic.

Just for laughs I turned on all warnings on my Ubuntu-64 platform,
gcc-4.1.2, and did not see this warning.  I did however see warnings
about use of "pragma" and the "U" and "LU" suffixes.  It suggested
indenting the "#" at the beginning of the "pragma" lines to hide
them from tradional C.

Glenn




More information about the Zlib-devel mailing list