Re: Some memory allocations in gin fastupdate code are a bit brain dead

2018-12-19 Thread David Rowley
On Thu, 20 Dec 2018 at 05:44, Tom Lane wrote: > I don't think this is quite bulletproof against overflow, especially > in view of the rather careless mixing of int32 and uint32 variables > that exists here. The easiest way to make it bulletproof is to add > an explicit test, so I did that and pus

Re: Some memory allocations in gin fastupdate code are a bit brain dead

2018-12-19 Thread Tom Lane
David Rowley writes: > On Wed, 19 Dec 2018 at 04:24, Tom Lane wrote: >> Also, do we need to worry about integer overflow? > Good point. I didn't think of it before, but the previous code would > have ensured that we got an ERROR before any overflow could have > occurred as the repalloc() would

Re: Some memory allocations in gin fastupdate code are a bit brain dead

2018-12-19 Thread David Rowley
On Wed, 19 Dec 2018 at 04:24, Tom Lane wrote: > > David Rowley writes: > > I recently stumbled upon the following code in ginfast.c: > > while (collector->ntuples + nentries > collector->lentuples) > > { > > collector->lentuples *= 2; > > collector->tuples = (IndexTuple *) repalloc(collec

Re: Some memory allocations in gin fastupdate code are a bit brain dead

2018-12-18 Thread Tom Lane
David Rowley writes: > I recently stumbled upon the following code in ginfast.c: > while (collector->ntuples + nentries > collector->lentuples) > { > collector->lentuples *= 2; > collector->tuples = (IndexTuple *) repalloc(collector->tuples, > sizeof(IndexTuple) * collector->lentuple

Some memory allocations in gin fastupdate code are a bit brain dead

2018-12-18 Thread David Rowley
I recently stumbled upon the following code in ginfast.c: while (collector->ntuples + nentries > collector->lentuples) { collector->lentuples *= 2; collector->tuples = (IndexTuple *) repalloc(collector->tuples, sizeof(IndexTuple) * collector->lentuples); } it does not seem very smar