From: Taylor Yu Date: Wed, 5 Apr 2017 18:52:48 +0000 (-0400) Subject: Make CEIL_DIV() slightly more overflow-safe X-Git-Tag: tor-0.3.1.1-alpha~180^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c5adab025852c68bc637c4fbfa34c44cde7397bb;p=thirdparty%2Ftor.git Make CEIL_DIV() slightly more overflow-safe --- diff --git a/src/common/util.h b/src/common/util.h index cfe47f07f2..18eb57f1bc 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -163,9 +163,9 @@ int64_t clamp_double_to_int64(double number); void simplify_fraction64(uint64_t *numer, uint64_t *denom); /* Compute the CEIL of a divided by b, for nonnegative a - * and positive b. Works on integer types only. Not defined if a+b can - * overflow. */ -#define CEIL_DIV(a,b) (((a)+(b)-1)/(b)) + * and positive b. Works on integer types only. Not defined if a+(b-1) + * can overflow. */ +#define CEIL_DIV(a,b) (((a)+((b)-1))/(b)) /* Return v if it's between min and max. Otherwise * return min if v is smaller than min, or max if