Extra zero byte converting mpz_t to a string

Hans Aberg haberg-1 at telia.com
Mon Apr 20 08:30:15 UTC 2015


> On 20 Apr 2015, at 07:14, Niels Möller <nisse at lysator.liu.se> wrote:
> 
> Hans Aberg <haberg-1 at telia.com> writes:
> 
>> The manual does not seem to say what should be used in the GMP
>> deallocator length l argument if one wants it to always work, as in
>> this code:
>>  char* cs = mpz_get_str(NULL, b, z);
>>  ..
>>  free_function(cs, l);
>> Possibly one should use l = strlen(cs) + 1, but then that has to be
>> computed also when not used.
> 
> strlen + 1 is right. The documentation for mpz_get_str is quite explicit
> about that:

Right, but you would not would want to compute it if the current free_function() does not use it.




More information about the gmp-bugs mailing list