lkml.org 
[lkml]   [2009]   [Sep]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Make sure the value in abs() does not get truncated if it is greater than 2^32
On Thu, 3 Sep 2009, Rolf Eike Beer wrote:

> I was just digging a bit around in linux/kernel.h and stumbled over the abs()
> makro. For me it looks as it would return wrong results on 64 bit platforms
> if the input value is greater than 2^32.
>

I think you are right.


> Signed-off-by: Rolf Eike Beer <eike-kernel@sf-tec.de>
> ---
> include/linux/kernel.h | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index d6320a3..1e6eb66 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -145,7 +145,7 @@ extern int _cond_resched(void);
> #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
>
> #define abs(x) ({ \
> - int __x = (x); \
> + long __x = (x); \
> (__x < 0) ? -__x : __x; \
> })
>
>

--
Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
Plain text mails only, please http://www.expita.com/nomime.html
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html



\
 
 \ /
  Last update: 2009-09-12 00:57    [W:0.058 / U:0.456 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site