riscv-software-src / riscv-software-src/opensbi
atomic_sub_return() negates a long
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 712
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I'm reviewing opensbi as part of Ubuntu's Main Inclusion Review process. It's just a quick look, not a full audit.
I noticed that atomic_sub_return() uses -value as part of its processing.
There's more negative long numbers than positive long numbers, on most platforms; on my amd64 Ubuntu 20.04 system:
LONG_MAX 9223372036854775807
LONG_MIN -9223372036854775808
LONG_MAX 7fffffffffffffff
LONG_MIN 8000000000000000
Trying to flip LONG_MIN with unary - leaves it unchanged:
$ cat negativelong.c
#include <stdio.h>
#include <limits.h>
int main(int argc, char* argv[]) {
long i = LONG_MIN;
printf("%ld negated: %ld\n", i, -i);
return 0;
}
$ make ./negativelong
make: 'negativelong' is up to date.
$ ./negativelong
-9223372036854775808 negated: -9223372036854775808
I honestly haven't got a clue if there is an actual problem here or not; it just seemed worth a few seconds to double-check.
Thanks
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at lib/sbi/riscv_atomic.c line 46 and inspect how atomic_sub_return() handles the negated value, including the LONG_MIN case described in the issue. Reproduce or reason through the behavior on the supported platform and establish whether it causes an incorrect result; done means the concern is resolved with an appropriate code or test change if a defect is confirmed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100