rds1983 / StbSharp

C# port of the famous C framework
69 stars 8 forks source link

Incorrect Generated Code #7

Closed ForeverZer0 closed 5 years ago

ForeverZer0 commented 5 years ago

Was looking through the StbImageWrite.Generated.cs files, and noticed this...

if (256 <= 143)
{
    // Removed for brevity
}
else if (256 <= 255)
{
    // Removed for brevity
}
else if (256 <= 279)
{
    // Removed for brevity
}

I am going to assume this portion did not generate correctly, as 256 is never going to be less than 143 or 255, and always be less than 279.

rds1983 commented 5 years ago

It is simply copy of the original C code. Check this line https://github.com/nothings/stb/blob/c72a95d766b8cbf5514e68d3ddbf6437ac9425b1/stb_image_write.h#L938

And then definition of macro stbiw__zlib_huff: https://github.com/nothings/stb/blob/c72a95d766b8cbf5514e68d3ddbf6437ac9425b1/stb_image_write.h#L851

ForeverZer0 commented 5 years ago

I see, looks to be some macro-magic gone awry. Was trying compare against the C code with -E passed to the compiler, but it is unintelligible. Either way, doesn't hurt anything, just a few small unreachable branches in a large method, using cheap integer comparison. I haven't check the IL, it probably makes it a no-op anyways.