From ccfe2690f4466c832c388bf86a72f24a96ef041c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Draszik?= Date: Fri, 14 Feb 2020 02:56:21 +0000 Subject: [PATCH] cmock_generator_plugin_callback: allow usage with Clang scan-build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Running a project through Clang's scan-build produces countless warnings like build/test/mocks/mock_handleTroubleEvents.c:321:5: warning: Value stored to 'call_instance' is never read call_instance = CMOCK_GUTS_NONE; ^ ~~~~~~~~~~~~~~~ scan-build correctly determines that in the following snippet UNITY_CLR_DETAILS(); if (Mock.checkForActiveTroubleAfterDebounce_CallbackFunctionPointer != NULL) call_instance = CMOCK_GUTS_NONE; call_instance = Mock.startStopTimer_CallInstance; as generated by Ceedling / CMock, the first assignment to call_instance is completely unused. The sheer amount of warnings makes it very hard to impossible to spot real problems in one's code, and creates huge code analysis reports that just distract from actual problems in one's code. Without being too invasive, we can instruct scan-build to ignore this dead store using https://clang-analyzer.llvm.org/faq.html#dead_store Signed-off-by: André Draszik --- lib/cmock_generator_plugin_callback.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/cmock_generator_plugin_callback.rb b/lib/cmock_generator_plugin_callback.rb index 76593f0..d4d1bd3 100644 --- a/lib/cmock_generator_plugin_callback.rb +++ b/lib/cmock_generator_plugin_callback.rb @@ -82,7 +82,9 @@ class CMockGeneratorPluginCallback def mock_verify(function) func_name = function[:name] - " if (Mock.#{func_name}_CallbackFunctionPointer != NULL)\n call_instance = CMOCK_GUTS_NONE;\n" + " if (Mock.#{func_name}_CallbackFunctionPointer != NULL)\n {\n" \ + " call_instance = CMOCK_GUTS_NONE;\n" \ + " (void)call_instance;\n }\n" end end