Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle when arch_prctl fails. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eatnumber1
Copy link

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.

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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant