[PATCH] mini-gmp: pass correct old_size to custom reallocate function

Marco Bodrato bodrato at mail.dm.unipi.it
Mon Mar 9 12:43:03 UTC 2020


Ciao,

Il 2020-03-09 13:04 minux ha scritto:
> Hello,

> IMO, it's better to keep behavior of mini-gmp and gmp as consistent as
> possible, to minimize surprises.

I agree!

> I added a check for out-of-range base to the beginning of mpq_get_str

I'd prefer to let checking ranges outside of the mpq code.
If res==NULL for whatever reason, goto ret is incorrect anyway: the next 
instruction is strlen(res).

> Please take another look at the attached patch. All existing comments 
> addressed.

If the goal of the patch is to "pass correct old_size to custom 
reallocate [and free] function[s]", I'd simply suggest the following:

@@ -498,9 +498,9 @@

      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 * sizeof (char), (lden 
+ len) * sizeof (char));
      memcpy (res + len, rden, lden);
-    gmp_free_func (rden, 0);
+    gmp_free_func (rden, lden * sizeof (char));
    }

    res [len - 1] = '/';


Ĝis,
m


More information about the gmp-devel mailing list