on master help sign in
Fix minigmp assertion failure

Constructing an integer from an empty string should give 0, rather than a failure (this was a problem with minigmp only, not gmp)

commita38b7de7a9e4f442ef3d5ceed58cd35fe5196d29 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSat 10 Sep 2016, 15:00 (10 years ago) parent566b6a0
1 file changed+17−12
rts/idris_gmp.c+17−12
rts/idris_gmp.c+17−12
@@ -23,20 +23,25 @@ VAL MKBIGI(int val) {
2323}
2424
2525VAL MKBIGC(VM* vm, char* val) {
26− idris_requireAlloc(IDRIS_MAXGMP);
27− mpz_t* bigint;
28−
29− VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
30− idris_doneAlloc();
31− bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
32−
33− mpz_init(*bigint);
34− mpz_set_str(*bigint, val, 10);
26+ if (*val == '\0') {
27+ return MKBIGI(0);
28+ }
29+ else {
30+ idris_requireAlloc(IDRIS_MAXGMP);
31+ mpz_t* bigint;
32+
33+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
34+ idris_doneAlloc();
35+ bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
36+
37+ mpz_init(*bigint);
38+ mpz_set_str(*bigint, val, 10);
3539
36− SETTY(cl, CT_BIGINT);
37− cl -> info.ptr = (void*)bigint;
40+ SETTY(cl, CT_BIGINT);
41+ cl -> info.ptr = (void*)bigint;
3842
39− return cl;
43+ return cl;
44+ }
4045}
4146
4247VAL MKBIGM(VM* vm, void* big) {