[GiNaC-devel] [PATCH 5/6] ncmul::eval(): don't write beyond the end of the vector.
Alexei Sheplyakov
varg at metalica.kh.ua
Mon Aug 10 07:41:39 CEST 2009
Hi Jens,
On Sun, Aug 09, 2009 at 10:21:53PM +0200, Jens Vollinga wrote:
> Yes, it improves the allocation,
unsignedvector rettypes;
// rettypes.size() == 0
rettypes.reserve(assocseq.size());
// rettypes.size() == 0 since reserve() does NOT change the size of a vector.
rettypes[i] = cit->return_type();
// Illegal according to the standard. Appears to work with some implementations
// and segfault with others (i.e. m$vc)
So the patch does fix the access beyond the vector boundary (as the commit
message implies).
> and then it does something that looks as if someone prefers to program
> in Python ...
I guess you mean this hunk:
> - switch (rettypes[i] = cit->return_type()) {
> + rettypes[i] = cit->return_type();
> + switch (rettypes[i]) {
It makes code less obscure (IMNSHO), but it's not strictly necessary.
Feel free to skip it.
Best regards,
Alexei
More information about the GiNaC-devel
mailing list