Skip to content

Commit a0c00fd

Browse files
committed
Fix IntervalSetDomain div overflow including 0
1 parent 133b6e5 commit a0c00fd

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/cdomain/value/cdomains/int/intervalSetDomain.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,12 @@ struct
364364

365365
let div ?no_ov ik x y =
366366
let rec interval_div x y =
367+
let (neg, pos) = IArith.div x y in
368+
let r = List.filter_map Fun.id [neg; pos] in
367369
if leq (of_int ik Ints_t.zero |> fst) [y] then
368-
top_of ik (* TODO: should somehow handle overflow like normal intervals? *)
369-
else (
370-
let (neg, pos) = IArith.div x y in
371-
List.filter_map Fun.id [neg; pos] (* should always be singleton, because if there's a negative and a positive side, then it must've included zero, which is already handled by previous case *)
372-
)
370+
top_of ik @ r (* keep r because they might overflow, but top doesn't *)
371+
else
372+
r (* should always be singleton, because if there's a negative and a positive side, then it must've included zero, which is already handled by previous case *)
373373
in
374374
binary_op_concat_with_norm interval_div ik x y
375375

tests/regression/39-signed-overflows/15-div-minus-1.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
$ goblint --enable warn.deterministic --enable ana.int.interval_set 15-div-minus-1.c
1212
[Warning][Integer > Overflow][CWE-190] Signed integer overflow (15-div-minus-1.c:5:9-5:26)
13+
[Warning][Integer > Overflow][CWE-190] Signed integer overflow (15-div-minus-1.c:7:5-7:16)
1314
[Warning][Integer > Overflow][CWE-190] Signed integer overflow (15-div-minus-1.c:9:9-9:20)
1415
[Warning][Integer > DivByZero][CWE-369] Second argument of division might be zero (15-div-minus-1.c:7:5-7:16)
1516
[Info][Deadcode] Logical lines of code (LLoC) summary:

0 commit comments

Comments
 (0)