~mdw
/
catacomb
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
7a051b7
)
progs/factorial.c: Reject negative inputs.
author
Mark Wooding
<mdw@distorted.org.uk>
Fri, 27 Feb 2015 14:44:45 +0000
(14:44 +0000)
committer
Mark Wooding
<mdw@distorted.org.uk>
Fri, 27 Feb 2015 14:46:19 +0000
(14:46 +0000)
Otherwise they get reduced mod 2^large, and the program takes forever.
It's not like we'd get a better answer by using the full-on Gamma
function, so just report an error.
progs/factorial.c
patch
|
blob
|
blame
|
history
diff --git
a/progs/factorial.c
b/progs/factorial.c
index
a46debd
..
975c698
100644
(file)
--- a/
progs/factorial.c
+++ b/
progs/factorial.c
@@
-135,7
+135,7
@@
int main(int argc, char *argv[])
xx = mp_readstring(MP_NEW, argv[optind], &p, 0);
while (isspace((unsigned char)*p))
p++;
- if (!xx || *p || MP_CMP(xx, >, ulmax))
+ if (!xx || *p || MP_CMP(xx,
<, MP_ZERO) || MP_CMP(xx,
>, ulmax))
die(EXIT_FAILURE, "bad integer `%s'", argv[optind]);
x = mp_toulong(xx);
mp_drop(xx);