Page 1 of 1

Improper use of TZCustomElementList?

Posted: 02.10.2024, 14:46
by stoffman
Hi,

Reading the code I found something that I don’t fully understand and I hope someone can clarify it.

TZCustomElementList has 2 properties Count and Capacity. Count being the actual number of elements in the list and Capacity being the size of the memory allocated for the list. Capacity must be equal or bigger than Count and it is an implementation detail of the list as it can reduce the number of memory allocations for the list.

In ZDbcPostgreSqlStatement.pas there are 12 references for Capacity which look like an error to me.

For example in line 982, the code checks if the parameter is out of bounds of the list, the user can still reference an item that was not yet allocated but it will still be valid.

https://github.com/frones/ZeosLib/blob/ ... t.pas#L982

This is just one example, there are more cases like that.

Or am I missing something?

Thanks