From a0caf0ede22220a63d641e636498fa87f9d66277 Mon Sep 17 00:00:00 2001 From: Russell Harmon Date: Thu, 1 Jul 2021 17:51:47 -0700 Subject: [PATCH] Correctly handle when arch_prctl fails. 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`. --- src/cpuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpuid.c b/src/cpuid.c index b326d4c..94af67b 100644 --- a/src/cpuid.c +++ b/src/cpuid.c @@ -364,7 +364,7 @@ void cpuid_init(bool secure) if (!strcmp(conf, "help")) show_help_and_die(); - bool faulting_disabled; + int faulting_disabled; if ((faulting_disabled = arch_prctl(ARCH_GET_CPUID, 0)) < 0) secure_err(1, "CPUID faulting feature inaccessible");