Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes a bug in the method that computes C padding. #1308

Merged
merged 1 commit into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/bap_c/bap_c_size.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ class base (m : model) = object(self)
let align = Size.in_bits (self#alignment t) in
match (align - offset mod align) mod align with
| 0 -> None
| n -> Some (Size.of_int_exn n)
| n -> match Size.of_int n with
| Error _ -> None
| Ok s -> Some s

method alignment (t : Bap_c_type.t) : size =
let byte = `r8 in
Expand Down Expand Up @@ -99,13 +101,12 @@ class base (m : model) = object(self)

method structure : compound unqualified -> Int.t option =
fun {Spec.t={Compound.fields}} ->
let padding t offset =
let align = Size.in_bits (self#alignment t) in
(align - offset mod align) mod align in
List.fold fields ~init:(Some 0) ~f:(fun sz (_,field) -> match sz with
| None -> None
| Some sz -> match self#bits field with
| None -> None
| Some sz' ->
let pad = match self#padding field sz with
| None -> 0
| Some sz -> Size.in_bits sz in
Some (sz + sz' + pad))
| Some sz' -> Some (sz + sz' + padding field sz))
end
9 changes: 5 additions & 4 deletions lib/bap_c/bap_c_size.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ class base : model -> object
- if type is void then alignment is 8 bits.*)
method alignment : t -> size

(** [padding t off] computes a required padding at given offset
that should be inserted before value of type [t] to satisfy
the alignment restriction for [t], as determined by the
[alignment] method. *)
(* this method was deprecated as
1) it has an incorrect type (padding can have any number of bits)
2) padding is fully defined by the alignemnt and there is no
need to parameterize it. *)
method padding : t -> bits -> size option
[@@deprecated "since [2021-05] this method is ignored"]


(** [array spec] if array [spec] is complete, then returns a
Expand Down