File tree Expand file tree Collapse file tree 3 files changed +11
-2
lines changed
src/cdomain/value/cdomains/int
tests/regression/39-signed-overflows Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -448,7 +448,12 @@ module IntDomTupleImpl = struct
448448 {f2_ovc = (fun (type a ) (module I : SOverflow with type t = a ) ?no_ov -> I. div ?no_ov ik)}
449449
450450 let rem ik =
451- map2 ik {f2= (fun (type a ) (module I : SOverflow with type t = a ) ?no_ov -> I. rem ik)}
451+ map2ovc ~op: (Binop Mod ) ik
452+ {f2_ovc = (fun (type a ) (module I : SOverflow with type t = a ) ?no_ov x y ->
453+ (* C11 6.5.5.6: if [x/y] is not representable (i.e. overflows), then [x%y] is undefined (let's also call it overflow) *)
454+ let (_, div_ov) = I. div ?no_ov ik x y in
455+ (I. rem ik x y, div_ov) (* TODO: should [div] overflow check be moved into each [rem] in each int domain? *)
456+ )}
452457
453458 let lt ik =
454459 map2 ik {f2= (fun (type a ) (module I : SOverflow with type t = a ) ?no_ov -> I. lt ik)}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ int main() {
66 int x , y ;
77 bad = x % y ; // WARN (div by zero and overflow, distinguished in cram test)
88 if (y != 0 ) {
9- bad = x % y ; // TODO WARN (overflow)
9+ bad = x % y ; // WARN (overflow)
1010 }
1111 return 0 ;
1212}
Original file line number Diff line number Diff line change 11TODO: should warn about overflow in all three % -s
22 $ goblint -- enable warn . deterministic -- enable ana. int . interval 17 -mod-minus-1. c
3+ [Warning][Integer > Overflow][CWE-190] Signed integer overflow in % (17 -mod-minus-1. c: 7 : 5 -7: 16 )
4+ [Warning][Integer > Overflow][CWE-190] Signed integer overflow in % (17 -mod-minus-1. c: 9 : 9 -9: 20 )
35 [Warning][Integer > DivByZero][CWE-369] Second argument of modulo might be zero (17 -mod-minus-1. c: 7 : 5 -7: 16 )
46 [Info][Deadcode] Logical lines of code (LLoC) summary:
57 live: 6
@@ -8,6 +10,8 @@ TODO: should warn about overflow in all three %-s
810
911TODO: should warn about overflow in all three % -s
1012 $ goblint -- enable warn . deterministic -- enable ana. int . interval_set 17 -mod-minus-1. c
13+ [Warning][Integer > Overflow][CWE-190] Signed integer overflow in % (17 -mod-minus-1. c: 7 : 5 -7: 16 )
14+ [Warning][Integer > Overflow][CWE-190] Signed integer overflow in % (17 -mod-minus-1. c: 9 : 9 -9: 20 )
1115 [Warning][Integer > DivByZero][CWE-369] Second argument of modulo might be zero (17 -mod-minus-1. c: 7 : 5 -7: 16 )
1216 [Info][Deadcode] Logical lines of code (LLoC) summary:
1317 live: 6
You can’t perform that action at this time.
0 commit comments