From: Andrew Cooper Date: Fri, 15 Jan 2016 15:02:00 +0000 (+0000) Subject: Avoid overflow in compare_extable_entry() when entries are far appart X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=d49a4a797514c019c7015f191c5f49e522d7a999;p=people%2Froyger%2Fxen-test-framework.git Avoid overflow in compare_extable_entry() when entries are far appart Constrain the return value to strictly between -1 and 1. Without this, sorting extable entries which are further than 2GB apart fails, as the calculation overflows the return value. Signed-off-by: Andrew Cooper --- diff --git a/common/extable.c b/common/extable.c index d5b47c9..b28dd78 100644 --- a/common/extable.c +++ b/common/extable.c @@ -33,7 +33,12 @@ static int compare_extable_entry(const void *_l, const void *_r) { const struct extable_entry *l = _l, *r = _r; - return l->fault - r->fault; + if ( l->fault == r->fault ) + return 0; + else if ( l->fault > r->fault ) + return 1; + else + return -1; } static void swap_extable_entry(void *_l, void *_r)