Skip to content

Floating point exception in builtin.c #1176

@moraxy

Description

@moraxy

Tested against the current master and jqplay.org

$ ./jq -n 'infinite%-1'                                                                                
Floating point exception

gdb

Program received signal SIGFPE, Arithmetic exception.
0x0000000000493836 in f_mod (jq=<optimized out>, input=..., a=..., b=...) at src/builtin.c:263
263         return jv_number((intmax_t)jv_number_value(a) % (intmax_t)jv_number_value(b));
(gdb) bt
#0  0x0000000000493836 in f_mod (jq=<optimized out>, input=..., a=..., b=...) at src/builtin.c:263
#1  0x0000000000415510 in jq_next (jq=jq@entry=0x716150) at src/execute.c:786
#2  0x00000000004077e8 in process (jq=0x716150, value=..., flags=flags@entry=0, dumpopts=dumpopts@entry=645) at src/main.c:151
#3  0x0000000000406607 in main (argc=<optimized out>, argv=<optimized out>) at src/main.c:546
(gdb) l
 258     static jv f_mod(jq_state *jq, jv input, jv a, jv b) {
 259       jv_free(input);
 260       if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) {
 261         if ((intmax_t)jv_number_value(b) == 0)
 262           return type_error2(a, b, "cannot be divided (remainder) because the divisor is zero");
>263         return jv_number((intmax_t)jv_number_value(a) % (intmax_t)jv_number_value(b));
 264       } else {
 265         return type_error2(a, b, "cannot be divided (remainder)");
 266       }
 267     }

Possibly related to #750 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions