diff options
-rw-r--r-- | get_str.c | 2 | ||||
-rw-r--r-- | out_str.c | 5 |
2 files changed, 4 insertions, 3 deletions
@@ -105,7 +105,7 @@ char *mpfr_get_str(char *str, mp_exp_t *expptr, int base, size_t n, /* computes the number of characters needed */ q = ((SIGN(op)<0) ? 1 : 0) + n + 1; - if (str==NULL) str0=str=malloc(q); + if (str==NULL) str0=str=(*_mp_allocate_func)(q); if (SIGN(op)<0) *str++='-'; mpz_get_str(str, base, bz); /* n digits of mantissa */ if (strlen(str)==n+1) f++; /* possible due to rounding */ @@ -7,12 +7,13 @@ size_t mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op, unsigned char rnd_mode) { - char *s; size_t l; mp_exp_t e; + char *s,*s0; size_t l; mp_exp_t e; if (FLAG_NAN(op)) { fprintf(stream, "NaN"); return 3; } if (!NOTZERO(op)) { fprintf(stream, "0"); return 1; } s = mpfr_get_str(NULL, &e, base, n_digits, op, rnd_mode); + s0 = s; /* for op=3.1416 we have s = "31416" and e = 1 */ l = strlen(s)+1; @@ -28,6 +29,6 @@ size_t mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op, fprintf(stream, "%s", s); } - free(s); + (*_mp_free_func)(s0, l); return l; } |