Messages in this thread Patch in this message | | | From | Paul Rusty Russell <> | Subject | [PATCH] 2.3.3: new include | Date | Sun, 30 May 1999 14:18:14 +0930 |
| |
The following macros make people think about signedness.
diff -urN linux-2.3/include/linux/minmax.h linux/include/linux/minmax.h --- /mnt/devel/linux-2.3/include/linux/minmax.h Thu Jan 1 09:30:00 1970 +++ /mnt/devel/linux-netfilter/include/linux/minmax.h Tue Apr 27 01:44:01 1999 @@ -0,0 +1,27 @@ +#ifndef _LINUX_MINMAX_H +#define _LINUX_MINMAX_H + +/* From arch/i386/kernel/smp.c: + * + * Why isn't this somewhere standard ?? + * + * Maybe because this procedure is horribly buggy, and does + * not deserve to live. Think about signedness issues for five + * seconds to see why. - Linus + */ + +/* Use which one you mean explicitly. You have been warned. */ +#include <linux/types.h> + +/* Two signed, return a signed. */ +#define SMAX(a,b) ((ssize_t)(a)>(ssize_t)(b) ? (ssize_t)(a) : (ssize_t)(b)) +#define SMIN(a,b) ((ssize_t)(a)<(ssize_t)(b) ? (ssize_t)(a) : (ssize_t)(b)) + +/* Two unsigned, return an unsigned. */ +#define UMAX(a,b) ((size_t)(a)>(size_t)(b) ? (size_t)(a) : (size_t)(b)) +#define UMIN(a,b) ((size_t)(a)<(size_t)(b) ? (size_t)(a) : (size_t)(b)) + +/* Two unsigned, return a signed. */ +#define SUMAX(a,b) ((size_t)(a)>(size_t)(b) ? (ssize_t)(a) : (ssize_t)(b)) +#define SUMIN(a,b) ((size_t)(a)<(size_t)(b) ? (ssize_t)(a) : (ssize_t)(b)) +#endif There are 121 #defines of MIN/MAX/min/max in 2.3.3. 12 are brace-deficient.
Rusty. -- Tridge, Raster, DaveM, Cort, maddog... Where will you be 9-11 July 1999? http://www.linux.org.au/projects/calu
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |