Index: sys/sys/param.h =================================================================== RCS file: /cvsroot/src/sys/sys/param.h,v retrieving revision 1.424 diff -p -u -r1.424 param.h --- sys/sys/param.h 20 Dec 2012 08:03:44 -0000 1.424 +++ sys/sys/param.h 21 Mar 2013 15:43:11 -0000 @@ -370,7 +370,14 @@ #endif #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) #define rounddown(x,y) (((x)/(y))*(y)) -#define roundup2(x, m) (((x) + (m) - 1) & ~((m) - 1)) +/* + * The x - x term forces m - 1 to be converted to the width of x before + * taking the complement, so that if m is unsigned int and x is larger, + * then m will be extended before the complement -- and, critically, + * not *zero*-extended after the complement as it would be without the + * correction because it is unsigned. + */ +#define roundup2(x, m) (((x) + (m) - 1) & ~(((m) - 1) + ((x) - (x)))) #define powerof2(x) ((((x)-1)&(x))==0) /* Macros for min/max. */