FujiExpoMidPointShift bug in LibRaw 0.18

Hi LibRaw team,

I ran into a problem where the FujiExpoMidPointShift variable has a different value in the debug vs release builds. This seems to be a bug in LibRaw 0.18. It worked fine in LibRaw 0.17. Here is how to reproduce.

In the following Google Drive folder is a Fuji X-Pro1 RAF test image.


For convenience, the folder also contains two dcraw_emu Windows binaries that I built using LibRaw 0.18. One is debug build and the other is a release build. I added a printf at the end of dcraw_emu like this:

   fprintf(stderr, "FujiExpoMidPointShift = %f\n", RawProcessor.imgdata.makernotes.fuji.FujiExpoMidPointShift);

When you run dcraw_emu_debug on the test image, you will get:

FujiExpoMidPointShift = -0.720000

LibRaw 0.17 also produces the same value (note: the FujiExpoMidPointShift variable was in the imgdata.color data structure in LibRaw 0.17), so I assume that -0.72 is the correct value.

When you run dcraw_emu_release on the test image, you will get:

FujiExpoMidPointShift = 0.001528

The bug seems to be in the Windows release build compiled using Visual Studio 2015. I've compiled the same library on the Mac and it works fine.

Can you reproduce this bug?




It looks like VS2013 (in my case) changes the order of execution in this line:
imgdata.makernotes.fuji.FujiExpoMidPointShift = ((short)get2()) / fMAX(1.0f, get2());
Replacing it with
float val0 = get2();
float val1 = get2();
imgdata.makernotes.fuji.FujiExpoMidPointShift = ((short)val0) / fMAX(1.0f,val1);

fixes the problem.

Is divide args should be evaluated left to right or not?

-- Alex Tutubalin @LibRaw LLC


Hi Alex,

Thanks for the quick fix!