]> git.ipfire.org Git - thirdparty/libvirt.git/commit
Don't use enums in TPM struct fields
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 6 Jun 2018 16:37:49 +0000 (17:37 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 6 Jun 2018 16:46:31 +0000 (17:46 +0100)
commited29219f217f6e42b2a4c0881206c5ff22bfd0d1
treec0a4c4822f61c66dc47d7c6cfac5f89a7e1473b4
parentfab2e49d3c290bfd122aad39b9484f60c5354256
Don't use enums in TPM struct fields

When using an enum in a struct field, the compiler is free to decide to
make it an unsigned type if it desires. This in turn leads to bugs when
code does

    if ((def->foo = virDomainFooTypeFromString(str)) < 0)
       ...

because 'def->foo' can't technically have an unsigned value from the
compiler's POV. While it is possible to add (int) casts in the code
example above, this is not desirable because it is easy to miss out
such casts. eg the code fixed here caused an error with clang builds

../../src/conf/domain_conf.c:12838:73: error: comparison of unsigned enum expression < 0 is always false [-Werror,-Wtautological-compare]
        if ((def->version = virDomainTPMVersionTypeFromString(version)) < 0) {
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h