I get the warning identicalInnerCondition on the second if statement. But in this case the two ifs are needed. The firts is to check if we actual need to aquire the lock (is someone else has it, it can take some time). The second is to be sure that the pointer is still valid once the lock is aquired (as anaother locking party might have invalidated it).
I don't know if this kind of dynamic behavior should be checked by cppcheck
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think it would be good with a bit of context. I can't see what exceptions is for instance. I assume it's some kind of global variable? Is it volatile?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Which would be true for a mono-threaded process or a non-static local variable.
But in the case of concurrent call to func(), i could have change between the two if's.
Last edit: Lionel Gimbert 2020-12-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm not sure if this should be marked as false positive or not. I have the following code
I get the warning identicalInnerCondition on the second if statement. But in this case the two ifs are needed. The firts is to check if we actual need to aquire the lock (is someone else has it, it can take some time). The second is to be sure that the pointer is still valid once the lock is aquired (as anaother locking party might have invalidated it).
I don't know if this kind of dynamic behavior should be checked by cppcheck
I think it would be good with a bit of context. I can't see what exceptions is for instance. I assume it's some kind of global variable? Is it
volatile
?It is a bit of code from my work. I will provide some context after the holidays vacation
It's a kind of false positive I seen when dealing with multi-threading protection.
I can provide a code example that also trigger the issue:
Which would be true for a mono-threaded process or a non-static local variable.
But in the case of concurrent call to
func()
,i
could have change between the twoif
's.Last edit: Lionel Gimbert 2020-12-28