libvirtcpuid icon indicating copy to clipboard operation
libvirtcpuid copied to clipboard

Correctly handle when arch_prctl fails.

Open eatnumber1 opened this issue 3 years ago • 0 comments

The current code is written as follows:

bool faulting_disabled;
if ((faulting_disabled = arch_prctl(ARCH_GET_CPUID, 0)) < 0)
    secure_err(1, "CPUID faulting feature inaccessible");

arch_prctl will return -1 on failure, however bool cannot represent the value -1. This produces the following warning in clang when -Wtautological-constant-compare is enabled)

third_party/libvirtcpuid/src/cpuid.c:368:61: error: result of comparison of constant 0 with expression of type 'bool' is always false [-Werror,-Wtautological-constant-compare]
    if ((faulting_disabled = arch_prctl(ARCH_GET_CPUID, 0)) < 0)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~

The fix is to change faulting_disabled to an int so it can store the return value of arch_prctl.

eatnumber1 avatar Jul 02 '21 00:07 eatnumber1