@@ -291,7 +291,7 @@ struct
291291 ID. cast_to (Cilfacade. ptrdiff_ikind () ) offs_intdom, offsetTyp
292292 end
293293 in
294- let isAfterZero, isBeforeEnd = (ctx.ask (Queries. AllocMayBeOutOfBounds (e, addr_offs_casted, structOffset, currentSizeTyp) )) in
294+ let isAfterZero, isBeforeEnd = (ctx.ask (Queries. AllocMayBeOutOfBounds {exp = e;e1_offset = addr_offs_casted;struct_offset = structOffset;offset_typ = currentSizeTyp} )) in
295295 let isAfterZeroBool, isBeforeEndBool = (VDQ.ID. to_bool isAfterZero, VDQ.ID. to_bool isBeforeEnd) in
296296 begin match isAfterZeroBool with
297297 | None ->
@@ -435,61 +435,61 @@ struct
435435
436436 let query ctx (type a ) (q : a Queries.t ): a Queries.result =
437437 match q with
438- | Queries. AllocMayBeOutOfBounds ( e , i , o , t ) ->
438+ | Queries. AllocMayBeOutOfBounds { exp = e ; e1_offset = i ; struct_offset = o ; offset_typ = t } ->
439439 begin match i with
440440 | i when not @@ ID. is_bot i ->
441- if M. tracing then M. trace " OOB" " e=%a i=%a o=%a\n " d_exp e ID. pretty i ID. pretty o;
442- let expOffset = match e with
443- | Lval (Var v , _ ) -> i
444- | BinOp (binop , e1 , e2 , t ) when binop = PlusPI || binop = IndexPI || binop = MinusPI ->
445- let ptr_deref_type = get_ptr_deref_type @@ typeOf e1 in
446- begin match ptr_deref_type with
447- | Some typ ->
448- let e2Offset = eval_ptr_offset_in_binop ctx e2 typ in (* add offset of e2*)
449- begin match e2Offset with
450- | `Lifted e2Offset ->
451- begin
452- try if binop = MinusPI then
453- ID. sub i e2Offset
454- else
455- ID. add i e2Offset
456- with IntDomain. ArithmeticOnIntegerBot _ -> ID. top_of (Cilfacade. ptrdiff_ikind () )
457- end
458- | `Top | `Bot -> ID. top_of (Cilfacade. ptrdiff_ikind () )
441+ if M. tracing then M. trace " OOB" " e=%a i=%a o=%a\n " d_exp e ID. pretty i ID. pretty o;
442+ let expOffset = match e with
443+ | Lval (Var v , _ ) -> i
444+ | BinOp (binop , e1 , e2 , t ) when binop = PlusPI || binop = IndexPI || binop = MinusPI ->
445+ let ptr_deref_type = get_ptr_deref_type @@ typeOf e1 in
446+ begin match ptr_deref_type with
447+ | Some typ ->
448+ let e2Offset = eval_ptr_offset_in_binop ctx e2 typ in (* add offset of e2*)
449+ begin match e2Offset with
450+ | `Lifted e2Offset ->
451+ begin
452+ try if binop = MinusPI then
453+ ID. sub i e2Offset
454+ else
455+ ID. add i e2Offset
456+ with IntDomain. ArithmeticOnIntegerBot _ -> ID. top_of (Cilfacade. ptrdiff_ikind () )
459457 end
460- | _ -> ID. top_of (Cilfacade. ptrdiff_ikind () )
458+ | `Top | `Bot -> ID. top_of (Cilfacade. ptrdiff_ikind () )
461459 end
462- | _ ->failwith " unexpected expression in query AllocMayBeOutOfBounds \n "
463- in
464- if M. tracing then M. trace " OOB" " e=%a expOffset %a \n " d_exp e ID. pretty expOffset;
465- let isBeforeZero = ID. le (ID. of_int (Cilfacade. ptrdiff_ikind () ) Z. zero) expOffset in (* check for negative Indices*)
466-
467- let currentTypSize = size_of_type_in_bytes t in
468- let castedCurrentTypSize = ID. cast_to (Cilfacade. ptrdiff_ikind () ) currentTypSize in (* add size of type*)
469- let expOffset_CurrentTyPSize =
470- begin try ID. add expOffset castedCurrentTypSize
471- with IntDomain. ArithmeticOnIntegerBot _ -> ID. top_of (Cilfacade. ptrdiff_ikind () )
472- end
473- in
474- if M. tracing then M. trace " OOB" " current_index_size %a \n " ID. pretty currentTypSize;
475- if M. tracing then M. trace " OOB" " expOffset_plus_current_index_size %a \n " ID. pretty expOffset_CurrentTyPSize;
476- let expOffset_CurrentTypSize_StructOffset =
477- (try (ID. add o expOffset_CurrentTyPSize)
478- with IntDomain. ArithmeticOnIntegerBot _ -> ID. top_of (Cilfacade. ptrdiff_ikind () ))
479- in
480- if M. tracing then M. trace " OOB" " exp_Offset_plus_current_index_size_struct_offset %a \n " ID. pretty expOffset_CurrentTypSize_StructOffset;
481- let isBeforeEnd = match get_size_of_ptr_target ctx e with
482- | `Lifted size ->
483- let casted_e_size = ID. cast_to (Cilfacade. ptrdiff_ikind () ) size in
484- if M. tracing then M. trace " OOB" " casted_e_size %a \n " ID. pretty casted_e_size;
485- ID. le expOffset_CurrentTypSize_StructOffset casted_e_size
486- | `Top -> ID. top_of IInt
487- | `Bot -> ID. top_of IInt (* Ikind of ID comparisons*)
488- in
489- if M. tracing then M. trace " OOB" " result %a %a\n " ID. pretty isBeforeZero ID. pretty isBeforeEnd;
490- (`Lifted isBeforeZero,`Lifted isBeforeEnd)
491- | _ -> (ValueDomainQueries.ID. top () , ValueDomainQueries.ID. top() )
492- end
460+ | _ -> ID. top_of (Cilfacade. ptrdiff_ikind () )
461+ end
462+ | _ ->failwith " unexpected expression in query AllocMayBeOutOfBounds \n "
463+ in
464+ if M. tracing then M. trace " OOB" " e=%a expOffset %a \n " d_exp e ID. pretty expOffset;
465+ let isBeforeZero = ID. le (ID. of_int (Cilfacade. ptrdiff_ikind () ) Z. zero) expOffset in (* check for negative Indices*)
466+
467+ let currentTypSize = size_of_type_in_bytes t in
468+ let castedCurrentTypSize = ID. cast_to (Cilfacade. ptrdiff_ikind () ) currentTypSize in (* add size of type*)
469+ let expOffset_CurrentTyPSize =
470+ begin try ID. add expOffset castedCurrentTypSize
471+ with IntDomain. ArithmeticOnIntegerBot _ -> ID. top_of (Cilfacade. ptrdiff_ikind () )
472+ end
473+ in
474+ if M. tracing then M. trace " OOB" " current_index_size %a \n " ID. pretty currentTypSize;
475+ if M. tracing then M. trace " OOB" " expOffset_plus_current_index_size %a \n " ID. pretty expOffset_CurrentTyPSize;
476+ let expOffset_CurrentTypSize_StructOffset =
477+ (try (ID. add o expOffset_CurrentTyPSize)
478+ with IntDomain. ArithmeticOnIntegerBot _ -> ID. top_of (Cilfacade. ptrdiff_ikind () ))
479+ in
480+ if M. tracing then M. trace " OOB" " exp_Offset_plus_current_index_size_struct_offset %a \n " ID. pretty expOffset_CurrentTypSize_StructOffset;
481+ let isBeforeEnd = match get_size_of_ptr_target ctx e with
482+ | `Lifted size ->
483+ let casted_e_size = ID. cast_to (Cilfacade. ptrdiff_ikind () ) size in
484+ if M. tracing then M. trace " OOB" " casted_e_size %a \n " ID. pretty casted_e_size;
485+ ID. le expOffset_CurrentTypSize_StructOffset casted_e_size
486+ | `Top -> ID. top_of IInt
487+ | `Bot -> ID. top_of IInt (* Ikind of ID comparisons*)
488+ in
489+ if M. tracing then M. trace " OOB" " result %a %a\n " ID. pretty isBeforeZero ID. pretty isBeforeEnd;
490+ (`Lifted isBeforeZero,`Lifted isBeforeEnd)
491+ | _ -> (ValueDomainQueries.ID. top () , ValueDomainQueries.ID. top() )
492+ end
493493 (* Queries.Result.top q *)
494494 | _ -> Queries.Result. top q
495495
0 commit comments