Protect against function-looking structs (Fixes #513)

This commit is contained in:
Mark VanderVoord
2026-06-19 15:10:14 -04:00
parent 85058d1407
commit 1ef72ca854
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -253,7 +253,7 @@ class CMockHeaderParser
# enums, unions, structs, and typedefs can all contain things (e.g. function pointers) that parse like function prototypes, so yank them
# forward declared structs are removed before struct definitions so they don't mess up real thing later. we leave structs keywords in function prototypes
source.gsub!(/^[\w\s]*struct[^;{}()]+;/m, '') # remove forward declared structs
source.gsub!(/^[\w\s]*(enum|union|struct|typedef)[\w\s]*\{[^}]+\}[\w\s*,]*;/m, '') # remove struct, union, and enum definitions and typedefs with braces
source.gsub!(/^[\w\s]*(enum|union|struct|typedef)[\w\s()]*\{[^}]+\}[\w\s*,]*;/m, '') # remove struct, union, and enum definitions and typedefs with braces
# remove problem keywords
source.gsub!(/(\W)(?:register|auto|restrict)(\W)/, '\1\2')
source.gsub!(/(\W)(?:static)(\W)/, '\1\2') unless cpp
+5
View File
@@ -111,3 +111,8 @@ inline int stuff(int num)
}
return reg;
}
/* it seems like CMock didn't love a func-looking struct before a func */
#define FOO_TYPE(a) foo_##a
struct FOO_TYPE(bar) { int baz; };
char b(void);