google / zopfli

Zopfli Compression Algorithm is a compression library programmed in C to perform very good, but slow, deflate or zlib compression.
Apache License 2.0
3.43k stars 330 forks source link

Compile error: divide or mod by zero in lodepng #162

Closed EwoutH closed 5 years ago

EwoutH commented 5 years ago

https://github.com/Mattlk13/zopfli/pull/3 introduced a compile error on zopfli\src\zopflipng\lodepng\lodepng_util.cpp, throwing an error C2124: divide or mod by zero. See this AppVeyor build as an example.

(ClCompile target) -> 
  C:\projects\zopfli\src\zopflipng\lodepng\lodepng_util.cpp(299,1): error C2124: divide or mod by zero [C:\projects\zopfli\cmake_build\libzopflipng.vcxproj]
    69 Warning(s)
    1 Error(s)

There are also a lot of open warnings that should be addressed.

jibsen commented 5 years ago

For reference; https://github.com/lvandeve/lodepng/issues/109

lvandeve commented 5 years ago

I updated lodepng again in commit 2f940d2b0b2a2894766d220785a435fd58d11679, does this fix it it for you?

Thank you

EwoutH commented 5 years ago

Unfortunately it did not: https://ci.appveyor.com/project/EwoutH/zopfli/builds/28410278/job/47laf4tngkfpjdpp

lvandeve commented 5 years ago

@EwoutH thanks for the second link. It shows an error on line 306:

"C:\projects\zopfli\src\zopflipng\lodepng\lodepng_util.cpp(306,1): error C2124: divide or mod by zero [C:\projects\zopfli\cmake_build\libzopflipng.vcxproj]"

But I have on line 306 the following, so it's odd that it gives a division through zero error for that particular line (and not earlier ones)

"return (x < -lodepng_flt_max) ? (y < 0 ? 0 : lodepng_flt_inf) :"

Can you please verify what you see on line 306?

Thank you

EwoutH commented 5 years ago

@lvandeve The same I'm afraid.

return (x < -lodepng_flt_max) ? (y < 0 ? 0 : lodepng_flt_inf) :

lvandeve commented 5 years ago

@EwoutH would you be willing to experiment a bit, e.g. removing "static const" from lodepng_fltzero" on line 285, or, remove "static const" from all three lines there?

The actual division through zero after commit 2f940d2 is on lines 286 and 287.

I haven't got this compiler available, and g++/clang++ don't give this error, so it would be very helpful to diagnose the problem that way.

Thank you :)

EwoutH commented 5 years ago

@lvandeve Yes, replacing static const float by float on line 285 solves the division error and makes it compile correctly!

There are still about 70 warnings though, including a lot in lodepng.

zvezdochiot commented 5 years ago

@EwoutH say:

There are still about 70 warnings though, including a lot in lodepng.

https://pastebin.com/

lvandeve commented 5 years ago

The referenced commit should fix the error.

Thanks for the warning log, that's independent from this issue, closing since it should be fixed