[File] [PATCH] Issue with libmagic and floating point exceptions
Christos Zoulas
christos at zoulas.com
Wed Dec 14 14:38:46 UTC 2022
On 2022-12-14 8:15 am, Vincent Mihalkovic wrote:
> Hi,
>
> The "Floating point exception (core dumped)" occurred when using
> libmagic internals
>
> on software with floating point exceptions enabled (FE_INVALID).
>
> Sample of what happens:
> """
> #include <stdio.h>
> #include <math.h>
> #include <fenv.h>
>
> int feenableexcept(int);
> int fedisableexcept(int);
>
> """
> int
> main(int argc, char *argv[])
> {
> union {
> int i;
> float f;
> } u[2];
> fedisableexcept(FE_ALL_EXCEPT);
> feenableexcept(FE_INVALID);
> u[0].i = -1; // NaN
> u[1].f = 1;
> printf("%d\n", u[0].f < u[1].f);
> //printf("%d\n", isless(u[0].f, u[1].f));
> return 0;
> }
> """
>
> $ gcc test.c -lm
> $ ./a.out
> Floating point exception (core dumped)
>
> The proposed fix (by Paolo Andrade) added a simple check using macros
> (__builtin_is{less,greater,unordered}) from math.h.
>
> More detailed description in:
> https://bugzilla.redhat.com/show_bug.cgi?id=2061557.
>
> Vincent Mihalkovic
Committed, thanks!
christos
More information about the File
mailing list