projects
/
platform
/
upstream
/
toybox.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
2a53f53
)
factor: catch integer overflow.
author
Rob Landley
<rob@landley.net>
Fri, 1 Aug 2014 23:50:46 +0000
(18:50 -0500)
committer
Rob Landley
<rob@landley.net>
Fri, 1 Aug 2014 23:50:46 +0000
(18:50 -0500)
Now factor
9223372036854775783
(largest positive 64 bit signed prime) takes a
couple minutes but gives the right answer.
toys/other/factor.c
patch
|
blob
|
history
diff --git
a/toys/other/factor.c
b/toys/other/factor.c
index
e3992a8
..
9dc1cca
100644
(file)
--- 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;
}