Prevent undefined behavior due to typedef array usage.

This commit is contained in:
John Lindgren
2018-12-04 18:22:53 -05:00
parent 789c5852b5
commit cfa46d6440
2 changed files with 12 additions and 5 deletions
+4 -1
View File
@@ -73,7 +73,10 @@ class CMockGeneratorUtils
if (arg[:ptr?] or @treat_as.include?(arg[:type]))
" #{dest} = #{arg[:name]};\n"
else
" memcpy(&#{dest}, &#{arg[:name]}, sizeof(#{arg[:type]}));\n"
assert_expr = "sizeof(#{arg[:name]}) == sizeof(#{arg[:type]}) ? 1 : -1"
comment = "/* add #{arg[:type]} to :treat_as_array if this causes an error */"
" memcpy(&#{dest}, &#{arg[:name]},\n" +
" sizeof(#{arg[:type]}[#{assert_expr}])); #{comment}\n"
end
end