summaryrefslogtreecommitdiffstats
path: root/dragonflybsd
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 /dragonflybsd
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 'dragonflybsd')
-rw-r--r--dragonflybsd/DragonFlyBSDProcess.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c
index bd209327..55e4fbac 100644
--- a/dragonflybsd/DragonFlyBSDProcess.c
+++ b/dragonflybsd/DragonFlyBSDProcess.c
@@ -110,6 +110,7 @@ void DragonFlyBSDProcess_writeField(const Process* this, RichString* str, Proces
long DragonFlyBSDProcess_compare(const void* v1, const void* v2) {
const DragonFlyBSDProcess *p1, *p2;
const Settings *settings = ((const Process*)v1)->settings;
+
if (settings->direction == 1) {
p1 = (const DragonFlyBSDProcess*)v1;
p2 = (const DragonFlyBSDProcess*)v2;
@@ -117,12 +118,13 @@ long DragonFlyBSDProcess_compare(const void* v1, const void* v2) {
p2 = (const DragonFlyBSDProcess*)v1;
p1 = (const DragonFlyBSDProcess*)v2;
}
+
switch ((int) settings->sortKey) {
// add Platform-specific fields here
case JID:
- return (p1->jid - p2->jid);
+ return SPACESHIP_NUMBER(p1->jid, p2->jid);
case JAIL:
- return strcmp(p1->jname ? p1->jname : "", p2->jname ? p2->jname : "");
+ return SPACESHIP_NULLSTR(p1->jname, p2->jname);
default:
return Process_compare(v1, v2);
}

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