Reputation: 8163
I have a static checker which complains about usage of strncmp in an if-condition, saying
Logical operation performed on expression with possible side effects.
Does strncmp have potential side effects or can I ignore this as false positive?
if (strncmp(something1, pCurEntry->something2, sizeof(pCurEntry->something2)) == 0)
Upvotes: 0
Views: 233
Reputation: 234875
std::strncmp
is not allowed to have a side effect (the c-style strings are passed const
for example). With the example you present, your static analyser is issuing a message in error.
But a good static analyser will "complain" about something like
(expression) ? n = strncmp(...) : 1
as it has a side effect of setting n
on only a subset of the possible branches. (MISRA disallows that.)
Upvotes: 1