Skip to content

Commit 204117c

Browse files
authored
Merge pull request #499 from bal-stan/cast-memcpy-dest-pointers
Always cast `memcpy` source pointers to `const void *`
2 parents 8ce7039 + 2bcc723 commit 204117c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/cmock_generator_utils.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def code_assign_argument_quickly(dest, arg)
7676
else
7777
assert_expr = "sizeof(#{arg[:name]}) == sizeof(#{arg[:type]}) ? 1 : -1"
7878
comment = "/* add #{arg[:type]} to :treat_as_array if this causes an error */"
79-
" memcpy((void*)(&#{dest}), (void*)(&#{arg[:name]}),\n" \
79+
" memcpy((void*)(&#{dest}), (const void*)(&#{arg[:name]}),\n" \
8080
" sizeof(#{arg[:type]}[#{assert_expr}])); #{comment}\n"
8181
end
8282
end

test/unit/cmock_generator_utils_test.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
expected3 = " cmock_call_instance->Expected_Kiwi = Kiwi;\n"
110110

111111
arg4 = { :name => "Lime", :const? => false, :type => 'LIME_T', :ptr? => false }
112-
expected4 = " memcpy((void*)(&cmock_call_instance->Expected_Lime), (void*)(&Lime),\n" +
112+
expected4 = " memcpy((void*)(&cmock_call_instance->Expected_Lime), (const void*)(&Lime),\n" +
113113
" sizeof(LIME_T[sizeof(Lime) == sizeof(LIME_T) ? 1 : -1])); /* add LIME_T to :treat_as_array if this causes an error */\n"
114114

115115
assert_equal(expected1, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg1))
@@ -135,7 +135,7 @@
135135
" cmock_call_instance->ReturnThruPtr_Kiwi_Used = 0;\n"
136136

137137
arg4 = { :name => "Lime", :const? => false, :type => 'LIME_T', :ptr? => false }
138-
expected4 = " memcpy((void*)(&cmock_call_instance->Expected_Lime), (void*)(&Lime),\n" +
138+
expected4 = " memcpy((void*)(&cmock_call_instance->Expected_Lime), (const void*)(&Lime),\n" +
139139
" sizeof(LIME_T[sizeof(Lime) == sizeof(LIME_T) ? 1 : -1])); /* add LIME_T to :treat_as_array if this causes an error */\n" +
140140
" cmock_call_instance->IgnoreArg_Lime = 0;\n"
141141

@@ -159,7 +159,7 @@
159159
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, stuff);\n" +
160160
"void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, stuff)\n{\n" +
161161
" cmock_call_instance->Expected_MyIntPtr = MyIntPtr;\n" +
162-
" memcpy((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType),\n" +
162+
" memcpy((void*)(&cmock_call_instance->Expected_MyMyType), (const void*)(&MyMyType),\n" +
163163
" sizeof(MY_TYPE[sizeof(MyMyType) == sizeof(MY_TYPE) ? 1 : -1])); /* add MY_TYPE to :treat_as_array if this causes an error */\n" +
164164
" cmock_call_instance->Expected_MyStr = MyStr;\n" +
165165
"}\n\n"
@@ -177,7 +177,7 @@
177177
" cmock_call_instance->Expected_MyIntPtr_Depth = MyIntPtr_Depth;\n" +
178178
" cmock_call_instance->IgnoreArg_MyIntPtr = 0;\n" +
179179
" cmock_call_instance->ReturnThruPtr_MyIntPtr_Used = 0;\n" +
180-
" memcpy((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType),\n" +
180+
" memcpy((void*)(&cmock_call_instance->Expected_MyMyType), (const void*)(&MyMyType),\n" +
181181
" sizeof(MY_TYPE[sizeof(MyMyType) == sizeof(MY_TYPE) ? 1 : -1])); /* add MY_TYPE to :treat_as_array if this causes an error */\n" +
182182
" cmock_call_instance->IgnoreArg_MyMyType = 0;\n" +
183183
" cmock_call_instance->Expected_MyStr = MyStr;\n" +

0 commit comments

Comments
 (0)