mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-08-05 02:37:50 +00:00
Address issue #196 to better deal with passing pointer types
This commit is contained in:
@@ -24,7 +24,13 @@ class CMockGeneratorPluginReturnThruPtr
|
||||
function[:args].each do |arg|
|
||||
if (@utils.ptr_or_str?(arg[:type]) and not arg[:const?])
|
||||
lines << "#define #{function[:name]}_ReturnThruPtr_#{arg[:name]}(#{arg[:name]})"
|
||||
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, sizeof(*#{arg[:name]}))\n"
|
||||
# If the pointer type actually contains an asterisk, we can do sizeof the type (super safe), otherwise
|
||||
# we need to do a sizeof the dereferenced pointer (which could be a problem if give the wrong size
|
||||
if (arg[:type][-1] == '*')
|
||||
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, sizeof(#{arg[:type][0..-2]}))\n"
|
||||
else
|
||||
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, sizeof(*#{arg[:name]}))\n"
|
||||
end
|
||||
lines << "#define #{function[:name]}_ReturnArrayThruPtr_#{arg[:name]}(#{arg[:name]}, cmock_len)"
|
||||
lines << " #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, (int)(cmock_len * (int)sizeof(*#{arg[:name]})))\n"
|
||||
lines << "#define #{function[:name]}_ReturnMemThruPtr_#{arg[:name]}(#{arg[:name]}, cmock_size)"
|
||||
|
||||
@@ -89,7 +89,7 @@ describe CMockGeneratorPluginReturnThruPtr, "Verify CMockGeneratorPluginReturnTh
|
||||
|
||||
expected =
|
||||
"#define Pine_ReturnThruPtr_tofu(tofu)" +
|
||||
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, sizeof(*tofu))\n" +
|
||||
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, sizeof(int))\n" +
|
||||
"#define Pine_ReturnArrayThruPtr_tofu(tofu, cmock_len)" +
|
||||
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, (int)(cmock_len * (int)sizeof(*tofu)))\n" +
|
||||
"#define Pine_ReturnMemThruPtr_tofu(tofu, cmock_size)" +
|
||||
|
||||
Reference in New Issue
Block a user