summaryrefslogtreecommitdiff
path: root/mini-gmp/mini-mpq.c
diff options
context:
space:
mode:
authorNiels M?ller <nisse@lysator.liu.se>2020-05-27 20:45:14 +0200
committerNiels M?ller <nisse@lysator.liu.se>2020-05-27 20:45:14 +0200
commit4bfa582d63c07f6c82ea5026b47d5421c8788417 (patch)
treebabdc0578b5c34ee6b79c24f08cc1d8e0b9d0fba /mini-gmp/mini-mpq.c
parent4604cb0c838d4bd9ad1616b8531f2defbb0671a9 (diff)
downloadgmp-4bfa582d63c07f6c82ea5026b47d5421c8788417.tar.gz
mini-gmp: Pass correct old_size to custom free and reallocate functions.
Contributed by Minux Ma.
Diffstat (limited to 'mini-gmp/mini-mpq.c')
-rw-r--r--mini-gmp/mini-mpq.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/mini-gmp/mini-mpq.c b/mini-gmp/mini-mpq.c
index fd9b43990..fb0010653 100644
--- a/mini-gmp/mini-mpq.c
+++ b/mini-gmp/mini-mpq.c
@@ -498,9 +498,9 @@ mpq_get_str (char *sp, int base, const mpq_t q)
mp_get_memory_functions (NULL, &gmp_reallocate_func, &gmp_free_func);
lden = strlen (rden) + 1;
- res = (char *) gmp_reallocate_func (res, 0, (lden + len) * sizeof (char));
+ res = (char *) gmp_reallocate_func (res, len, (lden + len) * sizeof (char));
memcpy (res + len, rden, lden);
- gmp_free_func (rden, 0);
+ gmp_free_func (rden, lden);
}
res [len - 1] = '/';
@@ -511,15 +511,15 @@ size_t
mpq_out_str (FILE *stream, int base, const mpq_t x)
{
char * str;
- size_t len;
+ size_t len, n;
void (*gmp_free_func) (void *, size_t);
str = mpq_get_str (NULL, base, x);
len = strlen (str);
- len = fwrite (str, 1, len, stream);
+ n = fwrite (str, 1, len, stream);
mp_get_memory_functions (NULL, NULL, &gmp_free_func);
- gmp_free_func (str, 0);
- return len;
+ gmp_free_func (str, len + 1);
+ return n;
}
int
@@ -540,11 +540,11 @@ mpq_set_str (mpq_t r, const char *sp, int base)
mp_get_memory_functions (&gmp_allocate_func, NULL, &gmp_free_func);
numlen = slash - sp;
- num = (char *) gmp_allocate_func ((numlen + 1) * sizeof (char));
+ num = (char *) gmp_allocate_func (numlen + 1);
memcpy (num, sp, numlen);
num[numlen] = '\0';
ret = mpz_set_str (mpq_numref(r), num, base);
- gmp_free_func (num, 0);
+ gmp_free_func (num, numlen + 1);
if (ret != 0)
return ret;