diff options
author | Rob Landley <rob@landley.net> | 2014-08-01 18:50:46 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2014-08-01 18:50:46 -0500 |
commit | b4062b0f9d096388c109b135066bcca901ef1dcd (patch) | |
tree | 403653aec69ac48dbecd04a05f81c33f99c97821 /toys/other | |
parent | 2a53f53d74167353cf434af59392c72a885cb7f6 (diff) | |
download | toybox-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.
Diffstat (limited to 'toys/other')
-rw-r--r-- | toys/other/factor.c | 4 |
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; } |