lodepng icon indicating copy to clipboard operation
lodepng copied to clipboard

silence warning 'possible loss of data' (win64)

Open haubi opened this issue 8 years ago • 2 comments

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 avatar Oct 11 '16 17:10 haubi

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.

haubi avatar Oct 12 '16 11:10 haubi

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.

stinos avatar Oct 12 '16 11:10 stinos