From 52d625ceb031221f440cc148047eeb07cc092bd9 Mon Sep 17 00:00:00 2001 From: gitoleg Date: Thu, 27 Jun 2019 10:07:58 -0400 Subject: [PATCH] preserves random values in Primus (#958) Primus generates a new random value (of course, if some generator policy was assigned) every time `Env.get` is called with an unbound variable. This PR changes this behaviour and makes Primus remember the generated value, i.e. bind such variable first time it's value was requested. --- lib/bap_primus/bap_primus_env.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/bap_primus/bap_primus_env.ml b/lib/bap_primus/bap_primus_env.ml index 81ba51c8f..8275be32a 100644 --- a/lib/bap_primus/bap_primus_env.ml +++ b/lib/bap_primus/bap_primus_env.ml @@ -108,7 +108,10 @@ module Make(Machine : Machine) = struct | Type.Mem (_,_) -> null | Type.Imm width -> match Map.find t.random var with | None -> Machine.raise (Undefined_var var) - | Some gen -> gen_word gen width >>= Value.of_word + | Some gen -> + gen_word gen width >>= Value.of_word >>= fun x -> + set var x >>= fun () -> + !!x let has var = Machine.Local.get state >>| fun t ->