diff options
-rw-r--r-- | get_str.c | 24 | ||||
-rw-r--r-- | inp_str.c | 12 | ||||
-rw-r--r-- | mpz_set_fr.c | 4 | ||||
-rw-r--r-- | print_raw.c | 12 | ||||
-rw-r--r-- | round.c | 4 |
5 files changed, 50 insertions, 6 deletions
@@ -62,7 +62,13 @@ char *mpfr_get_str(str, expptr, base, n, op, rnd_mode) neg = (MPFR_SIGN(op)<0) ? 1 : 0; if (MPFR_IS_INF(op)) { - if (str==NULL) str = (*_mp_allocate_func)(neg + 4); + if (str == NULL) { + str = (*_mp_allocate_func)(neg + 4); + if (str == NULL) { + fprintf (stderr, "Error in mpfr_get_str: no more memory available\n"); + exit (1); + } + } str0 = str; if (neg) { *str++ = '-'; } *str++ = 'I'; *str++ = 'n'; *str++ = 'f'; *str='\0'; @@ -70,7 +76,13 @@ char *mpfr_get_str(str, expptr, base, n, op, rnd_mode) } if (!MPFR_NOTZERO(op)) { - if (str==NULL) str = (*_mp_allocate_func)(neg + n + 1); + if (str == NULL) { + str = (*_mp_allocate_func)(neg + n + 1); + if (str == NULL) { + fprintf (stderr, "Error in mpfr_get_str: no more memory available\n"); + exit (1); + } + } str0 = str; if (MPFR_SIGN(op)<0) *str++ = '-'; for (f=0;f<n;f++) *str++ = '0'; @@ -186,7 +198,13 @@ char *mpfr_get_str(str, expptr, base, n, op, rnd_mode) /* computes the number of characters needed */ q = neg + n + 2; /* n+1 may not be enough for 100000... */ - if (str==NULL) str0=str=(*_mp_allocate_func)(q); + if (str == NULL) { + str0 = str = (*_mp_allocate_func)(q); + if (str == NULL) { + fprintf (stderr, "Error in mpfr_get_str: no more memory available\n"); + exit (1); + } + } if (neg) *str++='-'; mpz_get_str(str, base, bz); /* n digits of mantissa */ if (strlen(str)==n+1) { @@ -49,6 +49,10 @@ mpfr_inp_str (rop, stream, base, rnd_mode) alloc_size = 100; str = (char *) (*_mp_allocate_func) (alloc_size); + if (str == NULL) { + fprintf (stderr, "Error in mpfr_inp_str: no more memory available\n"); + exit (1); + } str_size = 0; nread = 0; @@ -67,6 +71,10 @@ mpfr_inp_str (rop, stream, base, rnd_mode) size_t old_alloc_size = alloc_size; alloc_size = alloc_size * 3 / 2; str = (char *) (*_mp_reallocate_func) (str, old_alloc_size, alloc_size); + if (str == NULL) { + fprintf (stderr, "Error in mpfr_inp_str: no more memory available\n"); + exit (1); + } } if (c == EOF || isspace (c)) break; @@ -80,6 +88,10 @@ mpfr_inp_str (rop, stream, base, rnd_mode) size_t old_alloc_size = alloc_size; alloc_size = alloc_size * 3 / 2; str = (char *) (*_mp_reallocate_func) (str, old_alloc_size, alloc_size); + if (str == NULL) { + fprintf (stderr, "Error in mpfr_inp_str: no more memory available\n"); + exit (1); + } } str[str_size] = 0; diff --git a/mpz_set_fr.c b/mpz_set_fr.c index 606eef5f1..7bd61e852 100644 --- a/mpz_set_fr.c +++ b/mpz_set_fr.c @@ -45,6 +45,10 @@ mpz_set_fr (z, f) if (ALLOC(z) < fn) { PTR(z) = (mp_ptr) (*_mp_reallocate_func) (PTR(z), ABS(SIZ(z))*BYTES_PER_MP_LIMB, fn*BYTES_PER_MP_LIMB); + if (PTR(z) == NULL) { + fprintf (stderr, "Error in mpz_set_fr: no more memory available\n"); + exit (1); + } ALLOC(z) = fn; } diff --git a/print_raw.c b/print_raw.c index b4e5385ca..e37ba56fa 100644 --- a/print_raw.c +++ b/print_raw.c @@ -71,7 +71,8 @@ mpfr_print_raw(x) mpfr_srcptr x; #endif { - char *str; + char *str; + unsigned long alloc_size; if (MPFR_IS_NAN(x)) printf("NaN"); else if (MPFR_IS_INF(x)) { @@ -86,11 +87,16 @@ mpfr_print_raw(x) + 11 for exponent (including sign) = 17 + MPFR_ABSSIZE(x) * BITS_PER_MP_LIMB */ - str = (char *) (*_mp_allocate_func) ((17 + MPFR_ABSSIZE(x) * BITS_PER_MP_LIMB)*sizeof(char)); + alloc_size = 17 + MPFR_ABSSIZE(x) * BITS_PER_MP_LIMB; + str = (char *) (*_mp_allocate_func) (alloc_size * sizeof(char)); + if (str == NULL) { + fprintf (stderr, "Error in mpfr_print_raw: no more memory available\n"); + exit (1); + } mpfr_get_str_raw(str, x); printf("%s", str); - (*_mp_free_func) (str, (17 + MPFR_ABSSIZE(x) * BITS_PER_MP_LIMB)*sizeof(char)); + (*_mp_free_func) (str, alloc_size * sizeof(char)); } } @@ -193,6 +193,10 @@ mpfr_round(x, rnd_mode, prec) if (nw > MPFR_ABSSIZE(x)) { MPFR_MANT(x) = (mp_ptr) (*_mp_reallocate_func) (MPFR_MANT(x), MPFR_ABSSIZE(x)*BYTES_PER_MP_LIMB, nw * BYTES_PER_MP_LIMB); + if (MPFR_MANT(x) == NULL) { + fprintf (stderr, "Error in mpfr_round: no more memory available\n"); + exit (1); + } MPFR_SIZE(x) = nw; /* new number of allocated limbs */ } |