Pārlūkot izejas kodu

Use safe comparisons in oopcmp

master
Ian Piumarta pirms 4 gadiem
vecāks
revīzija
5e7538a2f7
1 mainītis faili ar 14 papildinājumiem un 8 dzēšanām
  1. +14
    -8
      object.c

+ 14
- 8
object.c Parādīt failu

@ -328,14 +328,20 @@ int oopcmp(oop a, oop b)
type_t ta = getType(a), tb = getType(b);
if (ta == tb) {
switch (getType(a)) {
case Integer:
return getInteger(a) - getInteger(b);
case String:
return strcmp(get(a, String, value), get(b, String, value));
default:
if (a < b) return -1;
if (a > b) return 1;
return 0;
case Integer: {
int l= getInteger(a), r= getInteger(b);
if (l < r) return -1;
if (l > r) return 1;
return 0;
}
case String:
return strcmp(get(a, String, value), get(b, String, value));
default: {
intptr_t l= (intptr_t)a, r= (intptr_t)b;
if (l < r) return -1;
if (l > r) return 1;
return 0;
}
}
}
return ta - tb;

Notiek ielāde…
Atcelt
Saglabāt