<div dir="ltr">Hi,<div><br></div><div>The "Floating point exception (core dumped)" occurred when using libmagic internals</div><div>on software with floating point exceptions enabled (FE_INVALID).</div><div><div><br>Sample of what happens:<br>"""<br>#include <stdio.h><br>#include <math.h><br>#include <fenv.h><br><br>int feenableexcept(int);<br>int fedisableexcept(int);<br><br></div><div>"""<br>int<br>main(int argc, char *argv[])<br>{<br>  union {<br>    int   i;<br>    float f;<br>  } u[2];<br>  fedisableexcept(FE_ALL_EXCEPT);<br>  feenableexcept(FE_INVALID);<br>  u[0].i = -1;  // NaN<br>  u[1].f = 1;<br>  printf("%d\n", u[0].f < u[1].f);<br>  //printf("%d\n", isless(u[0].f, u[1].f));<br>  return 0;<br>}<br>"""<br><br>$ gcc test.c -lm<br>$ ./a.out<br>Floating point exception (core dumped)<br></div></div><div><br></div><div>The proposed fix (by Paolo Andrade) added a simple check using macros (__builtin_is{less,greater,unordered}) from math.h.</div><div><br></div><div>More detailed description in: <a href="https://bugzilla.redhat.com/show_bug.cgi?id=2061557">https://bugzilla.redhat.com/show_bug.cgi?id=2061557</a>.<br></div><div><br></div><div>Vincent Mihalkovic</div><div><br></div><div><br></div></div>