From f756eeaf554edee2c906fac358c6ab3501414836 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Tue, 16 Jun 2026 18:14:51 -0400 Subject: [PATCH] Fix handling of array of pointers (Fixes issue #450) --- lib/cmock_unityhelper_parser.rb | 7 +++- src/cmock.h | 2 +- .../test_interactions/array_handling.yml | 41 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/lib/cmock_unityhelper_parser.rb b/lib/cmock_unityhelper_parser.rb index 2bc79b3..b32eab0 100644 --- a/lib/cmock_unityhelper_parser.rb +++ b/lib/cmock_unityhelper_parser.rb @@ -16,7 +16,12 @@ class CMockUnityHelperParser def get_helper(ctype) lookup = ctype.gsub(/(?:^|(\S?)(\s*)|(\W))const(?:$|(\s*)(\S)|(\W))/, '\1\3\5\6').strip.gsub(/\s+/, '_') - return [@c_types[lookup], ''] if @c_types[lookup] + if @c_types[lookup] + # _ARRAY_ARRAY variants don't exist in Unity; use memory fallback instead + return [@fallback, ''] if @c_types[lookup].end_with?('_ARRAY_ARRAY') + + return [@c_types[lookup], ''] + end if lookup =~ /\*$/ lookup = lookup.gsub(/\*$/, '') diff --git a/src/cmock.h b/src/cmock.h index ea8a8db..755774c 100644 --- a/src/cmock.h +++ b/src/cmock.h @@ -12,7 +12,7 @@ #define CMOCK_VERSION_MAJOR 2 #define CMOCK_VERSION_MINOR 6 -#define CMOCK_VERSION_BUILD 3 +#define CMOCK_VERSION_BUILD 4 #define CMOCK_VERSION ((CMOCK_VERSION_MAJOR << 16) | (CMOCK_VERSION_MINOR << 8) | CMOCK_VERSION_BUILD) /* should be big enough to index full range of CMOCK_MEM_MAX */ diff --git a/test/system/test_interactions/array_handling.yml b/test/system/test_interactions/array_handling.yml index c01a0a2..49f5f51 100644 --- a/test/system/test_interactions/array_handling.yml +++ b/test/system/test_interactions/array_handling.yml @@ -49,6 +49,7 @@ void transform_grid(int grid[][4], int rows); void write_buffer(char (*dest)[10]); void read_buffers(int count, char (*buffers)[8]); + void process_handles(void *const handles[], int count); :source: :header: | @@ -61,6 +62,7 @@ void function_g(void); void function_h(void); void function_i(void); + void function_j(void); :code: | void function_a(void) @@ -128,6 +130,12 @@ read_buffers((int)3, bufs); } + void function_j(void) + { + void *const ptrs[] = {(void*)1, (void*)2, (void*)3}; + process_handles(ptrs, 3); + } + :tests: :common: | void setUp(void) {} @@ -598,4 +606,37 @@ function_i(); } + - :pass: TRUE + :should: 'pass when array of const void pointers matches expected' + :code: | + test() + { + void *const expected[] = {(void*)1, (void*)2, (void*)3}; + process_handles_Expect(expected, 3); + + function_j(); + } + + - :pass: FALSE + :should: 'detect mismatch in array of const void pointers' + :code: | + test() + { + void *const expected[] = {(void*)1, (void*)2, (void*)9}; + process_handles_Expect(expected, 3); + + function_j(); + } + + - :pass: TRUE + :should: 'pass when comparing subset of const void pointer array via ExpectWithArray' + :code: | + test() + { + void *const expected[] = {(void*)1, (void*)2}; + process_handles_ExpectWithArray(expected, 2, 3); + + function_j(); + } + ...