Skip to content

Commit

Permalink
Make sure the value in abs() does not get truncated if it is greater …
Browse files Browse the repository at this point in the history
…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: Rolf Eike Beer <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
DerDakon authored and torvalds committed Sep 23, 2009
1 parent d7d7561 commit a49c59c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/linux/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,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; \
})

Expand Down

0 comments on commit a49c59c

Please sign in to comment.