Skip to content

Commit

Permalink
Worry about sign overflow in comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed May 3, 2013
1 parent 964fe5a commit 6e7af9c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/lib/valuepair.c
Expand Up @@ -2039,11 +2039,23 @@ int paircmp(VALUE_PAIR *one, VALUE_PAIR *two)
case PW_TYPE_SHORT:
case PW_TYPE_INTEGER:
case PW_TYPE_DATE:
compare = two->vp_integer - one->vp_integer;
if (two->vp_integer < one->vp_integer) {
compare = -1;
} else if (two->vp_integer == one ->vp_integer) {
compare = 0;
} else {
compare = +1;
}
break;

case PW_TYPE_IPADDR:
compare = ntohl(two->vp_ipaddr) - ntohl(one->vp_ipaddr);
if (ntohl(two->vp_ipaddr) < ntohl(one->vp_ipaddr) ) {
compare = -1;
} else if (ntohl(two->vp_ipaddr) == ntohl(one->vp_ipaddr) ) {
compare = 0;
} else {
compare = +1;
}
break;

case PW_TYPE_IPV6ADDR:
Expand Down

0 comments on commit 6e7af9c

Please sign in to comment.