Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

haubi
Copy link

@haubi haubi commented Oct 11, 2016

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.

lodepng.cpp Outdated
@@ -3460,7 +3460,7 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in,
const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in,
unsigned w, unsigned h)
{
size_t i;
unsigned i;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just doesn't seem right: everywhere (?) i is used in this function it is compared with size_t or passed to a function taking size_t. So there shouldn't be any compiler warnings to begin with?

@haubi
Copy link
Author

haubi commented Oct 12, 2016

Comparing with size_t 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_tree_add(), 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
Copy link

stinos commented Oct 12, 2016

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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants