_mp_alloc vs ALLOC

bodrato at mail.dm.unipi.it bodrato at mail.dm.unipi.it
Sat Jun 9 10:56:13 CEST 2012


Ciao,

Il Ven, 8 Giugno 2012 10:28 pm, Marc Glisse ha scritto:
>    ((mp_ptr) res)[0] = ~ ((mp_ptr) res)[ALLOC (z) - 1];
>
> Won't valgrind complain about an uninitialized read here?

It shouldn't! I read from the manual of Valgrind:
http://valgrind.org/docs/manual/mc-manual.html#mc-manual.uninitvals

"It is important to understand that your program can copy around junk
(uninitialised) data as much as it likes. [...] A complaint is issued only
when your program attempts to make use of uninitialised data in a way that
might affect your program's externally-visible behaviour."

So, if the value is correctly overwritten before using it, Valgrind should
not complain.

I inserted the line for testing purposes, but it obviously is useless, it
can be removed!

> I think mpz_neg is a candidate for MPZ_NEWALLOC.

I think there are many, because the macro destroys the content only if a
memory enlargement is needed. E.g. mpz/tdiv_?_2exp.c are candidate for
_NEWALLOC, because no reallocation (i.e. no data loose) happen when source
and destination operands coincide.

Regards,
m

-- 
http://bodrato.it/software/



More information about the gmp-devel mailing list