diff options
author | Rasmus Villemoes <linux@rasmusvillemoes.dk> | 2014-12-11 00:51:27 +0100 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-11 02:41:11 +0100 |
commit | 74a5fef7cb0839c6b595f90c7914a62ac9d0bcf9 (patch) | |
tree | 82e34b9120005a8a764d25f9c91b17ada4445b05 /lib/lcm.c | |
parent | MAINTAINERS: update ivtv mailing lists as subscriber-only (diff) | |
download | linux-74a5fef7cb0839c6b595f90c7914a62ac9d0bcf9.tar.xz linux-74a5fef7cb0839c6b595f90c7914a62ac9d0bcf9.zip |
lib/lcm.c: ensure correct result whenever it fits
Ensure that lcm(a,b) returns the mathematically correct result, provided
it fits in an unsigned long. The current version returns garbage if a*b
overflows, even if the final result would fit.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/lcm.c')
-rw-r--r-- | lib/lcm.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/lcm.c b/lib/lcm.c index b9c8de461e9e..01b3aa922dda 100644 --- a/lib/lcm.c +++ b/lib/lcm.c @@ -7,7 +7,7 @@ unsigned long lcm(unsigned long a, unsigned long b) { if (a && b) - return (a * b) / gcd(a, b); + return (a / gcd(a, b)) * b; else if (b) return b; |