[ovs-dev] Coverity incorrect expression of HMAP_FOR_EACH_WITH_HASH

William Tu u9012063 at gmail.com
Wed Mar 18 03:32:52 UTC 2020


On Tue, Mar 17, 2020 at 5:39 PM Ben Pfaff <blp at ovn.org> wrote:
>
> 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).

Thanks!
Let me try it and get back to you.
William


More information about the dev mailing list