Skip to content

Commit 3d0495a

Browse files
committed
CHC: Address precondition on 'initialized(*argv)' for a simple hello world program
I couldn't figure out how to do it within the cCHCheckValid.ml match logic so I added the logic to the actual initialized checker. It now has a specific path that figures out if what we're looking at is argv[0] and marks it safe, closes the PO, and does not mark it for delegation. Probably not the cleanest solution, but it will do for now.
1 parent 282df68 commit 3d0495a

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

CodeHawk/CHC/cchanalyze/cCHPOCheckInitialized.ml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,37 @@ class initialized_checker_t
7171
(poq:po_query_int) (lval:lval) (invs:invariant_int list) =
7272
object (self)
7373

74+
method private check_program_name =
75+
if poq#is_command_line_argument (Lval lval) then
76+
let index = poq#get_command_line_argument_index (Lval lval) in
77+
if index == 0 then
78+
begin
79+
(* first index into argv is always safe, it is the program name *)
80+
poq#record_safe_result
81+
(DLocal [])
82+
("command-line argument "
83+
^ (string_of_int index)
84+
^ " is guaranteed initialized by the operating system");
85+
true
86+
end
87+
else
88+
false
89+
else
90+
false
91+
7492
method private check_command_line_argument =
7593
if poq#is_command_line_argument (Lval lval) then
7694
let index = poq#get_command_line_argument_index (Lval lval) in
7795
match poq#get_command_line_argument_count with
78-
| Some (inv,i) ->
79-
if index < i then
96+
| Some (inv, arg_count) ->
97+
if index < arg_count then
8098
begin
8199
poq#record_safe_result
82100
(DLocal [inv])
83101
("command-line argument "
84102
^ (string_of_int index)
85103
^ " is guaranteed initialized for argument count "
86-
^ (string_of_int i));
104+
^ (string_of_int arg_count));
87105
true
88106
end
89107
else
@@ -93,7 +111,7 @@ object (self)
93111
("command-line argument "
94112
^ (string_of_int index)
95113
^ " is not included in argument count of "
96-
^ (string_of_int i));
114+
^ (string_of_int arg_count));
97115
true
98116
end
99117
| _ ->
@@ -654,7 +672,10 @@ object (self)
654672
| _ -> false
655673

656674
method check_delegation =
657-
self#check_invs_delegation || self#check_lval_delegation
675+
if self#check_program_name then
676+
false
677+
else
678+
self#check_invs_delegation || self#check_lval_delegation
658679

659680
end
660681

0 commit comments

Comments
 (0)