diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2020-11-04 17:46:24 +0100 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2020-11-15 18:25:21 +0100 |
commit | 397b5c4bd09115d0df0846fee1b06797b68ae11c (patch) | |
tree | c0680d6e463d6325f87e67ef12d88dc2bd805812 /openbsd/OpenBSDProcess.c | |
parent | d785b1bbc3e30e41bacd283712455090eb2fe99c (diff) |
Introduce spaceship comparison for Processes
If currently two unsigned values are compared via `a - b`, in the case b
is actually bigger than a, the result will not be an negative number (as
-1 is expected) but a huge positive number as the subtraction is an
unsigned subtraction.
Avoid over-/underflow affected operations; use comparisons.
Modern compilers will generate sane code, like:
xor eax, eax
cmp rdi, rsi
seta al
sbb eax, 0
ret
Diffstat (limited to 'openbsd/OpenBSDProcess.c')
-rw-r--r-- | openbsd/OpenBSDProcess.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index 5eb61b16..1013d3b4 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -220,6 +220,7 @@ void OpenBSDProcess_writeField(const Process* this, RichString* str, ProcessFiel long OpenBSDProcess_compare(const void* v1, const void* v2) { const OpenBSDProcess *p1, *p2; const Settings *settings = ((const Process*)v1)->settings; + if (settings->direction == 1) { p1 = (const OpenBSDProcess*)v1; p2 = (const OpenBSDProcess*)v2; @@ -227,6 +228,7 @@ long OpenBSDProcess_compare(const void* v1, const void* v2) { p2 = (const OpenBSDProcess*)v1; p1 = (const OpenBSDProcess*)v2; } + switch (settings->sortKey) { // add OpenBSD-specific fields here default: |