提交 a49c59c0 编写于 作者: R Rolf Eike Beer 提交者: 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: NRolf Eike Beer <eike-kernel@sf-tec.de>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册