aboutsummaryrefslogtreecommitdiffstats
path: root/cparser
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2015-11-13 15:42:25 +0100
committerXavier Leroy <xavier.leroy@inria.fr>2015-11-13 15:42:25 +0100
commit9f0fcc2c52d136fb8891f1ce2e135bdb1273df19 (patch)
tree0a536a5e755514cad2acfad746282cadf7f8926c /cparser
parent3f24b362f5ac2aa252ee14f1b793ebbf2f69ff08 (diff)
downloadcompcert-9f0fcc2c52d136fb8891f1ce2e135bdb1273df19.tar.gz
compcert-9f0fcc2c52d136fb8891f1ce2e135bdb1273df19.zip
Issue #71: incorrect initialization of wchar_t arrays from wide string literal
Regression test added in regression/initializers.c
Diffstat (limited to 'cparser')
-rw-r--r--cparser/Elab.ml12
1 files changed, 6 insertions, 6 deletions
diff --git a/cparser/Elab.ml b/cparser/Elab.ml
index 27b650c0..d58d8be6 100644
--- a/cparser/Elab.ml
+++ b/cparser/Elab.ml
@@ -850,18 +850,18 @@ let init_char_array_string opt_size s =
Init_array (add_chars (Int64.pred size) [])
let init_int_array_wstring opt_size s =
- let len = Int64.of_int (List.length s) in
+ let a = Array.of_list s in
+ let len = Int64.of_int (Array.length a) in
let size =
match opt_size with
| Some sz -> sz
| None -> Int64.succ len (* include final 0 character *) in
- let rec add_chars i s init =
+ let rec add_chars i init =
if i < 0L then init else begin
- let (c, s') =
- match s with [] -> (0L, []) | c::s' -> (c, s') in
- add_chars (Int64.pred i) s' (Init_single (intconst c IInt) :: init)
+ let c = if i < len then a.(Int64.to_int i) else 0L in
+ add_chars (Int64.pred i) (Init_single (intconst c IInt) :: init)
end in
- Init_array (add_chars (Int64.pred size) (List.rev s) [])
+ Init_array (add_chars (Int64.pred size) [])
let check_init_type loc env a ty =
if wrap2 valid_assignment loc env a ty then ()