]> xenbits.xensource.com Git - libvirt.git/commit
util: xml: Fix confusing semantics of VIR_XML_PROP_OPTIONAL flag
authorPeter Krempa <pkrempa@redhat.com>
Wed, 21 Apr 2021 06:49:51 +0000 (08:49 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 21 Apr 2021 08:32:17 +0000 (10:32 +0200)
commit45a61cbf68a2459202b7eda4a01a56bfcb6be048
tree6ce2186fff9a77970514344943ca6baa6dff1478
parent497c3ecd7801a6521f621c9e154ac731de65e0b3
util: xml: Fix confusing semantics of VIR_XML_PROP_OPTIONAL flag

The new enum helpers use a set of flags to modify their behaviour, but
the declared set of flags is semantically confusing:

 typedef enum {
     VIR_XML_PROP_OPTIONAL = 0, /* Attribute may be absent */
     VIR_XML_PROP_REQUIRED = 1 << 0, /* Attribute may not be absent */

Since VIR_XML_PROP_OPTIONAL is declared as 0 any other flag shadows it
and makes it impossible to detect. The functions are not able to detect
a semantic nonsense of VIR_XML_PROP_OPTIONAL | VIR_XML_PROP_REQUIRED and
it's a perfectly valid statement for the compilers.

In general having two flags to do the same boolean don't make sense and
the implementation doesn't fix any shortcomings either.

To prevent mistakes, rename VIR_XML_PROP_OPTIONAL to VIR_XML_PROP_NONE,
so that there's always an enum value used with the calls but it doesn't
imply that the flag makes the property optional when the actual value is
0.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/cpu_conf.c
src/conf/domain_conf.c
src/conf/network_conf.c
src/util/virxml.h