Skip to contentSkip to conversation

minmax: allow comparisons of 'long long int' against 'unsigned char/short/int'

PATCH In review Matt Jan 2 participants 2 messages Jan 7, 2024

lore
Share & tools
lore

Matt Jan

author
#0 lore raw

PATCH 1/1 minmax: allow comparisons of 'long long int' against 'unsigned char/short/int'

Since 'unsigned int' get promoted to 'signed long long int' it is safe to compare them against an 'long long int' value.

---
 include/linux/minmax.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/minmax.h +1 -1
index 2ec559284a9f..61171286b468 100644
@@ -37,7 +37,7 @@
 
 #define __types_ok(x, y) 					\
 	(__is_signed(x) == __is_signed(y) ||			\
-		__is_signed((x) + 0) == __is_signed((y) + 0) ||	\
+		__is_signed((x) + 0ll) == __is_signed((y) + 0ll) ||	\
 		__is_noneg_int(x) || __is_noneg_int(y))
 
 #define __cmp_op_min <
Signature · 1 line
2.34.1
#1 lore raw

From: Matt Jan

Quoted 4 lines

Sent: 07 January 2024 20:11

Since 'unsigned int' get promoted to 'signed long long int' it is safe to compare them against an 'long long int' value.

Yes, but not as below.
That change would allow pretty much everything through since everything except 'unsigned long long' would be signed.

You'd need a much more complex check and the CPP bloat is pretty horrid already.

That particular check is there to promote unsigned char/short to signed int - which always happens.

David

Quoted 20 lines
---
 include/linux/minmax.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/minmax.h +1 -2
index 2ec559284a9f..61171286b468 100644
@@ -37,7 +37,7 @@
 
 #define __types_ok(x, y) 					\
 	(__is_signed(x) == __is_signed(y) ||			\
-		__is_signed((x) + 0) == __is_signed((y) + 0) ||	\
+		__is_signed((x) + 0ll) == __is_signed((y) + 0ll) ||	\
 		__is_noneg_int(x) || __is_noneg_int(y))
 
 #define __cmp_op_min <
--
Quoted 2 lines

2.34.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)