[ovs-dev] Coverity incorrect expression of HMAP_FOR_EACH_WITH_HASH

Ben Pfaff blp at ovn.org
Wed Mar 18 00:39:16 UTC 2020


On Tue, Mar 17, 2020 at 05:00:42PM -0700, William Tu wrote:
> Hi,
> 
> We're looking at the coverity results and there are lots of issues of
> Incorrect expression
> Assign_where_compare_meant: use of "=" where "==" may have been intended
> 
> Because in our source code, we have
> HMAP_FOR_EACH_WITH_HASH(id_node, node, hash, &pool->map) {
> ...
> 
> And Due to "(NODE = NULL)" in the CONDITION statement below:
> #define HMAP_FOR_EACH_WITH_HASH(NODE, MEMBER, HASH, HMAP)               \
>     for (INIT_CONTAINER(NODE, hmap_first_with_hash(HMAP, HASH), MEMBER); \
>          (NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER)) || (NODE = NULL); \
>          ASSIGN_CONTAINER(NODE, hmap_next_with_hash(&(NODE)->MEMBER),   \
>                           MEMBER))
> 
> While this is correct, I wonder how can we avoid this?

We could rewrite (NODE = NULL) as ((NODE = NULL), false).


More information about the dev mailing list