How to create a rule using RuleWizard to identify a comparison operator?
I am creating a Parasoft rule for C/C++test using RuleWizard that flags whenever a type std::string is used as an argument within certain function calls.
For example, this line should be a violation since it uses the variable 'mytestString' without a call to .c_str()
LOG_TRACE(7, "ParasoftTestProj::main() Some TRACE Message Data: %s", mytestString);
For the specific case when the argument is a ternary operator that uses a std::string as the condition, I want it to be ignored since it actually returns back a different value.
For example, the following line should be OK:
LOG_TRACE(7, "ParasoftTestProj::main() Some TRACE Message Data: %d", mytestString == "test" ? 1 : 0);
The rule that I have so far finds violations for both examples, and I need it to only flag the first example and ignore the second. A copy of my rule is attached.
Under my Declarations branch, the first two branches from that successfully find the violation in the first example but also finds a violation in the second example (which I want it to ignore). I tried to resolve this by adding the third branch below (Context a==b) to identify that if a std::string type is found to be used as a comparison it should be disregarded. However, this branch doesn't seem to be working as I intend it to. Is there a way to modify this branch to get my rule working? Or is there any other workaround that might solve this use case?