Re: [PATCH] MIN/MAX cleanup 2.1.125

Paul Rusty Russell (Paul.Russell@rustcorp.com.au)
Tue, 20 Oct 1998 03:52:27 +0930


In message <199810181705.MAA11170@duracef.shout.net> you write:
> I have some problems with linux/minmax.h. First it looks like you need
> to swap size_t and ssize_t. size_t is unsigned size, and ssize_t is
> signed size.

OK, I'm an idiot (shows how seldom it matters: ran fine <sigh>).
Apply enclosed patch.

> Second, what happens if someone uses SMIN or UMIN on two 64-bit quantities
> on a 32-bit machine, such as i386? I see silent truncation going on.

Yep. That's not done anywhere at the moment though.

Rusty.
--- linux-minmax/include/linux/minmax.h.~1~ Thu Oct 15 12:30:53 1998
+++ linux-minmax/include/linux/minmax.h Tue Oct 20 03:42:36 1998
@@ -14,14 +14,14 @@
#include <linux/types.h>

/* Two signed, return a signed. */
-#define SMAX(a,b) ((size_t)(a)>(size_t)(b) ? (size_t)(a) : (size_t)(b))
-#define SMIN(a,b) ((size_t)(a)<(size_t)(b) ? (size_t)(a) : (size_t)(b))
+#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) ((ssize_t)(a)>(ssize_t)(b) ? (ssize_t)(a) : (ssize_t)(b))
-#define UMIN(a,b) ((ssize_t)(a)<(ssize_t)(b) ? (ssize_t)(a) : (ssize_t)(b))
+#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) ((ssize_t)(a)>(ssize_t)(b) ? (size_t)(a) : (size_t)(b))
-#define SUMIN(a,b) ((ssize_t)(a)<(ssize_t)(b) ? (size_t)(a) : (size_t)(b))
+#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

--
 .sig lost in the mail.

- 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/