lvandeve / lodepng

PNG encoder and decoder in C and C++.
zlib License
2.06k stars 421 forks source link

silence warning 'possible loss of data' (win64) #44

Open haubi opened 7 years ago

haubi commented 7 years ago

When compiling for 64bit Windows, size_t and unsigned int are of different size, leading cl.exe to warning C4267: conversion from 'size_t' to 'unsigned int', possible loss of data

34 contains a different solution, but this one feels more straightforward.

haubi commented 7 years ago

Comparing with sizet doesn't generate a warning (no data loss actually), and the patch changes the readChunk??Xt() functions passing i as argument to to unsigned as well.

The warnings start with passing i to color_treeadd(), which casts the unsigned index to signed. And the readChunk??Xt() take size_t chunkLength , but assign to unsigned length as well, triggering the warning.

Alternative would be to use ssize_t (signed size_t) for the ColorTree::index, but ssize_t is not available on some platforms, nor is it used anywhere within lodepng yet.

stinos commented 7 years ago

Good point, should have checked more in detail. I think it would be better to fix all warnings at once though: when compiled with /W4 there's still a bucnh of conversion issues left.