On Tue, Nov 08, 2022 at 12:04:49 -0600, Jonathon Jongsma wrote:
On 11/7/22 1:45 AM, Ján Tomko wrote:
> On a Friday in 2022, Jonathon Jongsma wrote:
> > In virDomainVideoModelDefParseXML(), use the virXMLProp* functions
> > rather than reimplementing them with virXPath* functions.
> >
> > Signed-off-by: Jonathon Jongsma <jjongsma(a)redhat.com>
> > ---
> > src/conf/domain_conf.c | 78 +++++++++++++-----------------------------
> > 1 file changed, 23 insertions(+), 55 deletions(-)
> >
> > diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> > index 2e153db94f..552936c8b7 100644
> > --- a/src/conf/domain_conf.c
> > +++ b/src/conf/domain_conf.c
> > - if ((heads = virXPathString("string(./@heads)", ctxt))) {
> > - if (virStrToLong_uip(heads, NULL, 10, &def->heads) < 0) {
> > - virReportError(VIR_ERR_INTERNAL_ERROR,
> > - _("cannot parse video heads
'%s'"), heads);
> > - return -1;
> > - }
> > - }
> > + if ((rc = virXMLPropUInt(node, "heads", 10, VIR_XML_PROP_NONE,
> > &def->heads)) < 0)
> > + return -1;
>
> > + else if (rc == 0)
> > + def->heads = 1;
>
> This branch is not necessary - just like the previous code, def->heads
> is untouched if the attribute is not present.
This is unfortunately not true. virXMLPropUInt() actually sets *result = 0
at the very beginning of the function. So this branch is necessary unless we
change the implementation of virXMLPropUInt().
Changing the impl is out of question, but you can factor out the
implementation and provide a version which sets the default value to
something else than 0. We have these for signed integer parsing helpers
and for enums as virXMLPropEnumDefault.