From 1f14c0c645ce384406e405000375c7fb9e60cc9e Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Fri, 27 Feb 2015 14:44:45 +0000 Subject: [PATCH] progs/factorial.c: Reject negative inputs. 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/progs/factorial.c b/progs/factorial.c index a46debd1..975c698c 100644 --- 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); -- 2.11.0