aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-08-01 18:50:46 -0500
committerRob Landley <rob@landley.net>2014-08-01 18:50:46 -0500
commitb4062b0f9d096388c109b135066bcca901ef1dcd (patch)
tree403653aec69ac48dbecd04a05f81c33f99c97821
parent2a53f53d74167353cf434af59392c72a885cb7f6 (diff)
downloadtoybox-b4062b0f9d096388c109b135066bcca901ef1dcd.tar.gz
factor: catch integer overflow.
Now factor 9223372036854775783 (largest positive 64 bit signed prime) takes a couple minutes but gives the right answer.
-rw-r--r--toys/other/factor.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/toys/other/factor.c b/toys/other/factor.c
index e3992a8b..9dc1cca8 100644
--- a/toys/other/factor.c
+++ b/toys/other/factor.c
@@ -49,7 +49,9 @@ static void factor(char *s)
// test odd numbers.
for (ll=3; ;ll += 2) {
- if (ll*ll>l) {
+ long lll = ll*ll;
+
+ if (lll>l || lll<ll) {
if (l>1) printf(" %ld", l);
break;
}