Skip to content

Commit 8337906

Browse files
committed
CHB: handle scanf arguments side effects
1 parent 7610f74 commit 8337906

13 files changed

Lines changed: 350 additions & 100 deletions

CodeHawk/CHB/bchlib/bCHARMFunctionInterface.ml

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ let arm_vfp_params
630630

631631
let get_arm_format_spec_parameters
632632
(cpars: fts_parameter_t list)
633+
(isinput: bool)
633634
(argspecs: argspec_int list): fts_parameter_t list =
634635
let nextindex = (List.length cpars) + 1 in
635636
let update_core_reg aas (r: arm_reg_t) =
@@ -707,30 +708,35 @@ let get_arm_format_spec_parameters
707708
aas_start_state cpars in
708709
let (_, pars, _, _) =
709710
List.fold_left (fun (aas, accpars, varargindex, nxtindex) argspec ->
710-
let ftype = get_fmt_spec_type argspec in
711-
let ftype =
712-
if is_float ftype then
713-
promote_float ftype
714-
else if is_int ftype then
715-
promote_int ftype
716-
else
717-
ftype in
718-
let size_r = size_of_btype ftype in
719711
let name = "vararg_" ^ (string_of_int varargindex) in
720712
let (param, new_state) =
721-
match size_r with
722-
| Ok 4 -> get_arm_int_param_next_state 4 name ftype aas nxtindex
723-
| Ok 8 -> get_long_int_param_next_state 8 name ftype aas varargindex
724-
| Ok size ->
725-
raise
726-
(BCH_failure
727-
(LBLOCK [
728-
STR "Var-arg size: "; INT size; STR " not supported"]))
729-
| Error e ->
730-
raise
731-
(BCH_failure
732-
(LBLOCK [
733-
STR "Error in var-args: "; STR (String.concat "; " e)])) in
713+
if isinput then
714+
let vtype = get_fmt_spec_type argspec in
715+
let ftype = TPtr (vtype, []) in
716+
get_arm_int_param_next_state 4 name ftype aas nxtindex
717+
else
718+
let ftype = get_fmt_spec_type argspec in
719+
let ftype =
720+
if is_float ftype then
721+
promote_float ftype
722+
else if is_int ftype then
723+
promote_int ftype
724+
else
725+
ftype in
726+
let size_r = size_of_btype ftype in
727+
match size_r with
728+
| Ok 4 -> get_arm_int_param_next_state 4 name ftype aas nxtindex
729+
| Ok 8 -> get_long_int_param_next_state 8 name ftype aas varargindex
730+
| Ok size ->
731+
raise
732+
(BCH_failure
733+
(LBLOCK [
734+
STR "Var-arg size: "; INT size; STR " not supported"]))
735+
| Error e ->
736+
raise
737+
(BCH_failure
738+
(LBLOCK [
739+
STR "Error in var-args: "; STR (String.concat "; " e)])) in
734740
(new_state, param :: accpars, varargindex + 1, nxtindex + 1))
735741
(fmtaas, [], 1, nextindex) argspecs in
736742
pars

CodeHawk/CHB/bchlib/bCHARMFunctionInterface.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ val arm_vfp_params:
103103
?attrs:b_attributes_t -> ?varargs:bool -> bfunarg_t list -> fts_parameter_t list
104104

105105
val get_arm_format_spec_parameters:
106-
fts_parameter_t list -> argspec_int list -> fts_parameter_t list
106+
fts_parameter_t list -> bool -> argspec_int list -> fts_parameter_t list

0 commit comments

Comments
 (0)