Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schwarz committed Nov 28, 2023
1 parent d995cc9 commit 72476fb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
16 changes: 7 additions & 9 deletions src/cdomains/arrayDomain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1260,13 +1260,6 @@ struct
set
else
add_indexes (Z.succ i) max (MaySet.add i set) in
let update_must_indexes min_must_null must_nulls_set =
if min_must_null =. Z.zero then
MustSet.bot ()
else
(* if strlen < n, every byte starting from min_must_null is surely also transformed to null *)
add_indexes min_must_null n must_nulls_set
|> MustSet.M.filter (Z.gt n) in
let update_may_indexes min_may_null may_nulls_set =
if min_may_null =. Z.zero then
MaySet.top ()
Expand Down Expand Up @@ -1311,15 +1304,20 @@ struct
Nulls.add_all Possibly nulls
else
let (must, mays) = Nulls.add_interval Possibly (min_may_null, Z.pred n) nulls in
(must, mays |> MaySet.M.filter (Z.gt n)) (* TODO: this makes little sense *)
(must, mays |> MaySet.M.filter (fun x -> x <. n)) (* TODO: this makes little sense *)
else
let min_must_null = Nulls.min_elem Definitely nulls in
let min_may_null = Nulls.min_elem Possibly nulls in
(* warn if resulting array may not contain null byte *)
warn_no_null min_must_null true min_may_null;
(* if min_must_null = min_may_null, remove indexes >= n and add all indexes from minimal must/may null to n - 1 in the sets *)
if min_must_null =. min_may_null then
(update_must_indexes min_must_null must_nulls_set, update_may_indexes min_may_null may_nulls_set)
(if min_must_null =. Z.zero then
Nulls.full_set ()
else
let nulls = Nulls.add_interval Definitely (min_must_null, Z.pred n) nulls in
let nulls = Nulls.add_interval Possibly (min_may_null, Z.pred n) nulls in
Nulls.filter (fun x -> x <. n) nulls)
else
(MustSet.top (), update_may_indexes min_may_null may_nulls_set)
in
Expand Down
28 changes: 16 additions & 12 deletions src/cdomains/nullByteSet.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ module MustMaySet = struct

let empty () = (MustSet.top (), MaySet.bot ())

let full_set () = (MustSet.bot (), MaySet.top ())

let is_empty mode (musts, mays) =
match mode with
| Definitely -> MaySet.is_empty mays
Expand Down Expand Up @@ -123,21 +125,23 @@ module MustMaySet = struct
| Possibly -> (musts, MaySet.union (MaySet.of_list l) mays)

let add_interval ?maxfull mode (l,u) (musts, mays) =
match mode with
| Definitely -> failwith "todo"
| Possibly ->
let rec add_indexes i max set =
if Z.gt i max then
set
else
add_indexes (Z.succ i) max (MaySet.add i set)
in
let mays =
match maxfull with
| Some Some maxfull when Z.equal l Z.zero && Z.geq u maxfull ->
(musts, MaySet.top ())
MaySet.top ()
| _ ->
let rec add_indexes i max set =
if Z.gt i max then
set
else
add_indexes (Z.succ i) max (MaySet.add i set)
in
(musts, add_indexes l u mays)

add_indexes l u mays
in
match mode with
| Definitely -> (add_indexes l u musts, mays)
| Possibly -> (musts, mays)

let remove_interval mode (l,u) min_size (musts, mays) =
match mode with
| Definitely -> failwith "todo"
Expand Down

0 comments on commit 72476fb

Please sign in to comment.