[Zlib-devel] zLib warning with VC++ 2005 : simple fix

Gilles Vollant info at winimage.com
Fri Jul 15 12:51:02 EDT 2005


As I mentionned in previous email, I've warning when I compile tree.c with
Visual Studio 2005, by targeting 32 bits and using the "/Wp64" option.
All these warning are like
..\..\..\trees.c(773) : warning C4267: '=' : conversion from 'size_t' to
'ush', possible loss of data
When the send_code (which uses send_bits) macro is used.

I make a very simple fix, by modifying the line 223 of three.c :

The original line is:
    s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\

There is three possible modified line (remove all warning)

1) first option
    s->bi_buf = (ush)(val >> (Buf_size - s->bi_valid));\

2) second option
    s->bi_buf = (ush)((ush)val >> (Buf_size - s->bi_valid));\

3) third option
    s->bi_buf = (ush)(((ush)val) >> (Buf_size - s->bi_valid));\


the first option is the more easy to read, the two other are absolutely sure
not modify the behaviour. So I suggest the second option

the bi_buf member of internal_state structure is defined as usg (line 254 of
deflate.h)





More information about the Zlib-devel mailing list