summaryrefslogtreecommitdiffstats
path: root/openbsd
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-11-04 17:46:24 +0100
committerBenBE <BenBE@geshi.org>2020-11-15 18:25:21 +0100
commit397b5c4bd09115d0df0846fee1b06797b68ae11c (patch)
treec0680d6e463d6325f87e67ef12d88dc2bd805812 /openbsd
parentd785b1bbc3e30e41bacd283712455090eb2fe99c (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')
-rw-r--r--openbsd/OpenBSDProcess.c2
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:

© 2014-2024 Faster IT GmbH | imprint | privacy policy