lkml.org 
[lkml]   [2004]   [Aug]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[: Re: warning: comparison is always false due to limited range of data type]
Hi,

Le lun 09 aoû 2004 à 04:50:04 +0200, Paul Jackson a tapoté sur son clavier :
> Unfortunately, this patch uses the notorious "gcc warning suppression
> by obfuscation" technique.
>
> --- 2.6.8-rc2-mm2.orig/include/linux/highuid.h 2004-08-04 19:27:48.000000000 -0700
> +++ 2.6.8-rc2-mm2/include/linux/highuid.h 2004-08-08 19:03:47.000000000 -0700
> @@ -44,8 +44,8 @@ extern void __bad_gid(void);
> #ifdef CONFIG_UID16
>
> /* prevent uid mod 65536 effect by returning a default value for high UIDs */
> -#define high2lowuid(uid) ((uid) > 65535 ? (old_uid_t)overflowuid : (old_uid_t)(uid))
> -#define high2lowgid(gid) ((gid) > 65535 ? (old_gid_t)overflowgid : (old_gid_t)(gid))
> +#define high2lowuid(uid) ((uid) & ~0xFFFF ? (old_uid_t)overflowuid : (old_uid_t)(uid))
> +#define high2lowgid(gid) ((gid) & ~0xFFFF ? (old_gid_t)overflowgid : (old_gid_t)(gid))
> /*
> ...

Here is another approach. This should never warning, and should get
optimized away as needed.

Regards,
Samuel

--- linux-2.6.8.1-orig/include/linux/highuid.h 2003-10-08 22:20:06.000000000 +0200
+++ linux-2.6.8.1-perso/include/linux/highuid.h 2004-08-19 00:47:31.000000000 +0200
@@ -44,8 +44,8 @@
#ifdef CONFIG_UID16

/* prevent uid mod 65536 effect by returning a default value for high UIDs */
-#define high2lowuid(uid) ((uid) > 65535 ? (old_uid_t)overflowuid : (old_uid_t)(uid))
-#define high2lowgid(gid) ((gid) > 65535 ? (old_gid_t)overflowgid : (old_gid_t)(gid))
+#define high2lowuid(uid) ((sizeof(uid) > 2 ? (uid) : 0) > 65535 ? (old_uid_t)overflowuid : (old_uid_t)(uid))
+#define high2lowgid(gid) ((sizeof(gid) > 2 ? (gid) : 0) > 65535 ? (old_gid_t)overflowgid : (old_gid_t)(gid))
/*
* -1 is different in 16 bits than it is in 32 bits
* these macros are used by chown(), setreuid(), ...,
@@ -89,8 +89,8 @@
* Since these macros are used in architectures that only need limited
* 16-bit UID back compatibility, we won't use old_uid_t and old_gid_t
*/
-#define fs_high2lowuid(uid) ((uid) > 65535 ? (uid16_t)fs_overflowuid : (uid16_t)(uid))
-#define fs_high2lowgid(gid) ((gid) > 65535 ? (gid16_t)fs_overflowgid : (gid16_t)(gid))
+#define fs_high2lowuid(uid) ((sizeof(uid) > 2 ? (uid) : 0) > 65535 ? (uid16_t)fs_overflowuid : (uid16_t)(uid))
+#define fs_high2lowgid(gid) ((sizeof(gid) > 2 ? (gid) : 0) > 65535 ? (gid16_t)fs_overflowgid : (gid16_t)(gid))

#define low_16_bits(x) ((x) & 0xFFFF)
#define high_16_bits(x) (((x) & 0xFFFF0000) >> 16)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:05    [W:0.036 / U:1.256 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site