DentonW / DevIL

Developer's Image Library (DevIL) is a cross-platform image library utilizing a simple syntax to load, save, convert, manipulate, filter, and display a variety of images with ease. It is highly portable and has been ported to several platforms.

Home Page:http://openil.sourceforge.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cast from 'ILubyte* {aka unsigned char*}' to 'ILint {aka int}' loses precision

klausenbusk opened this issue · comments

Hello

I get the following, when trying to compile DevIL from ArchLinux.

git clone git@github.com:DentonW/DevIL.git
cd DevIL/DevIL
cmake .
make
[  1%] Building CXX object src-IL/CMakeFiles/IL.dir/src/il_rle.cpp.o
/home/kristian/Hentninger/DevIL/DevIL/src-IL/src/il_rle.cpp: In function 'ILboolean ilRleCompressLine(ILubyte*, ILuint, ILubyte, ILubyte*, ILuint*, ILenum)':
/home/kristian/Hentninger/DevIL/DevIL/src-IL/src/il_rle.cpp:20:52: error: cast from 'ILubyte* {aka unsigned char*}' to 'ILint {aka int}' loses precision [-fpermissive]
  const ILint bmp_pad_to_even = (ILint)(1 - ((ILint)q - *DestWidth) % 2);
                                                    ^
make[2]: *** [src-IL/CMakeFiles/IL.dir/build.make:1479: src-IL/CMakeFiles/IL.dir/src/il_rle.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:86: src-IL/CMakeFiles/IL.dir/all] Error 2
make: *** [Makefile:128: all] Error 2

Removing the q, seems to fix it, but I'm not sure if that yields other problems?

Regards Kristian

I'm also experiencing this issue in master 247fd43 from macOS.

Thanks for all your hard work, Denton!

Error

[  1%] Building CXX object src-IL/CMakeFiles/IL.dir/src/il_rle.cpp.o
/Users/andrewmcwatters/DevIL/DevIL/src-IL/src/il_rle.cpp:20:45: error: cast from
      pointer to smaller type 'ILint' (aka 'int') loses information
        const ILint bmp_pad_to_even = (ILint)(1 - ((ILint)q - *DestWidth) % 2);
                                                   ^~~~~~~~
1 error generated.
make[2]: *** [src-IL/CMakeFiles/IL.dir/src/il_rle.cpp.o] Error 1
make[1]: *** [src-IL/CMakeFiles/IL.dir/all] Error 2
make: *** [all] Error 2

Fix

/Users/andrewmcwatters/DevIL/DevIL/src-IL/src/il_rle.cpp:20:45

const ILint bmp_pad_to_even = (ILint)(1 - ((ILint)q - *DestWidth) % 2);
const ILint bmp_pad_to_even = (ILint)(1 - ((ILint)(size_t)q - *DestWidth) % 2);

References

[1] http://stackoverflow.com/questions/22419063/error-cast-from-pointer-to-smaller-type-int-loses-information-in-eaglview-mm

Result

DevIL successfully compiles.

Thanks, Visual Studio complained about that when compiling 64-bit but just gave a warning. I just committed your change.