Commit a49c59c0 authored by Rolf Eike Beer's avatar Rolf Eike Beer Committed by Linus Torvalds

Make sure the value in abs() does not get truncated if it is greater than 2^32

abs() will truncate the input if is it outside the 2^32 range.  Fix that
by assuming `long' input.

This might generate worse code in the common case.
Signed-off-by: default avatarRolf Eike Beer <eike-kernel@sf-tec.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d7d7561c
...@@ -146,7 +146,7 @@ extern int _cond_resched(void); ...@@ -146,7 +146,7 @@ extern int _cond_resched(void);
#define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
#define abs(x) ({ \ #define abs(x) ({ \
int __x = (x); \ long __x = (x); \
(__x < 0) ? -__x : __x; \ (__x < 0) ? -__x : __x; \
}) })
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment