Skip to content

Commit d3751b0

Browse files
committed
Fix semgrep warnings about Z.pred in bitwise operations
1 parent 6cdba20 commit d3751b0

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ struct
224224
| Some x, Some y -> (try of_int ik (f ik x y) with Division_by_zero | Invalid_argument _ -> (top_of ik,{underflow=false; overflow=false}))
225225
| _ -> (top_of ik,{underflow=true; overflow=true})
226226

227-
let min_val_bit_constrained n =
228-
if Ints_t.equal n Ints_t.zero then
229-
Ints_t.neg Ints_t.one
230-
else
231-
Ints_t.neg @@ Ints_t.shift_left Ints_t.one (Z.numbits (Z.sub (Z.abs @@ Ints_t.to_bigint n) Z.one))
227+
let min_val_bit_constrained n =
228+
if Ints_t.equal n Ints_t.zero then
229+
Ints_t.neg Ints_t.one
230+
else
231+
Ints_t.neg @@ Ints_t.shift_left Ints_t.one (Z.numbits (Z.pred (Z.abs @@ Ints_t.to_bigint n)))
232232

233-
let max_val_bit_constrained n =
233+
let max_val_bit_constrained n =
234234
let x = if Ints_t.compare n Ints_t.zero < 0 then Ints_t.sub (Ints_t.neg n) Ints_t.one else n in
235235
Ints_t.sub (Ints_t.shift_left Ints_t.one (Z.numbits @@ Z.abs @@ Ints_t.to_bigint x)) Ints_t.one
236236

@@ -248,13 +248,13 @@ struct
248248
let upper = max_val_bit_constrained @@ Ints_t.min x1 y1 in
249249
of_interval ik (Ints_t.zero, upper) |> fst
250250
| true, _, _, false | _, false, true, _ ->
251-
let lower = List.fold_left Ints_t.min Ints_t.zero
252-
(List.append (List.map min_val_bit_constrained [x1; y1])
253-
(List.map (fun i -> Ints_t.neg @@ Ints_t.add (max_val_bit_constrained i) Ints_t.one) [x2; y2])) in
251+
let lower = List.fold_left Ints_t.min Ints_t.zero
252+
(List.append (List.map min_val_bit_constrained [x1; y1])
253+
(List.map (fun i -> Ints_t.neg @@ Ints_t.add (max_val_bit_constrained i) Ints_t.one) [x2; y2])) in
254254
of_interval ik (lower, Ints_t.zero) |> fst
255-
| _ -> let lower = List.fold_left Ints_t.min Ints_t.zero
256-
(List.append (List.map min_val_bit_constrained [x1; y1])
257-
(List.map (fun i -> Ints_t.neg @@ Ints_t.add (max_val_bit_constrained i) Ints_t.one) [x2; y2])) in
255+
| _ -> let lower = List.fold_left Ints_t.min Ints_t.zero
256+
(List.append (List.map min_val_bit_constrained [x1; y1])
257+
(List.map (fun i -> Ints_t.neg @@ Ints_t.add (max_val_bit_constrained i) Ints_t.one) [x2; y2])) in
258258
let upper = List.fold_left Ints_t.max Ints_t.zero (List.map max_val_bit_constrained [x1;x2;y1;y2]) in
259259
of_interval ik (lower, upper) |> fst)
260260
| _ -> top_of ik

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,13 @@ struct
313313
| Some x, Some y -> (try of_int ik (f x y) with Division_by_zero | Invalid_argument _ -> (top_of ik,{overflow=false; underflow=false}))
314314
| _, _ -> (top_of ik,{overflow=false; underflow=false})
315315

316-
let min_val_bit_constrained n =
317-
if Ints_t.equal n Ints_t.zero then
318-
Ints_t.neg Ints_t.one
319-
else
320-
Ints_t.neg @@ Ints_t.shift_left Ints_t.one (Z.numbits (Z.sub (Z.abs @@ Ints_t.to_bigint n) Z.one))
316+
let min_val_bit_constrained n =
317+
if Ints_t.equal n Ints_t.zero then
318+
Ints_t.neg Ints_t.one
319+
else
320+
Ints_t.neg @@ Ints_t.shift_left Ints_t.one (Z.numbits (Z.pred (Z.abs @@ Ints_t.to_bigint n)))
321321

322-
let max_val_bit_constrained n =
322+
let max_val_bit_constrained n =
323323
let x = if Ints_t.compare n Ints_t.zero < 0 then Ints_t.sub (Ints_t.neg n) Ints_t.one else n in
324324
Ints_t.sub (Ints_t.shift_left Ints_t.one (Z.numbits @@ Z.abs @@ Ints_t.to_bigint x)) Ints_t.one
325325

@@ -374,13 +374,13 @@ struct
374374
let upper = max_val_bit_constrained @@ Ints_t.min x1 y1 in
375375
of_interval ik (Ints_t.zero, upper) |> fst
376376
| true, _, _, false | _, false, true, _ ->
377-
let lower = List.fold_left Ints_t.min Ints_t.zero
378-
(List.append (List.map min_val_bit_constrained [x1; y1])
379-
(List.map (fun i -> Ints_t.neg @@ Ints_t.add (max_val_bit_constrained i) Ints_t.one) [x2; y2])) in
377+
let lower = List.fold_left Ints_t.min Ints_t.zero
378+
(List.append (List.map min_val_bit_constrained [x1; y1])
379+
(List.map (fun i -> Ints_t.neg @@ Ints_t.add (max_val_bit_constrained i) Ints_t.one) [x2; y2])) in
380380
of_interval ik (lower, Ints_t.zero) |> fst
381-
| _ -> let lower = List.fold_left Ints_t.min Ints_t.zero
382-
(List.append (List.map min_val_bit_constrained [x1; y1])
383-
(List.map (fun i -> Ints_t.neg @@ Ints_t.add (max_val_bit_constrained i) Ints_t.one) [x2; y2])) in
381+
| _ -> let lower = List.fold_left Ints_t.min Ints_t.zero
382+
(List.append (List.map min_val_bit_constrained [x1; y1])
383+
(List.map (fun i -> Ints_t.neg @@ Ints_t.add (max_val_bit_constrained i) Ints_t.one) [x2; y2])) in
384384
let upper = List.fold_left Ints_t.max Ints_t.zero (List.map max_val_bit_constrained [x1;x2;y1;y2]) in
385385
of_interval ik (lower, upper) |> fst
386386

0 commit comments

Comments
 (0)