cppcheck: arrayIndexOutOfBounds report in stortree.cxx (store module)

Stephan Bergmann sbergman at redhat.com
Tue Jan 20 01:17:15 PST 2015


On 01/19/2015 10:52 PM, julien2412 wrote:
> However, I'm not sure to understand.
> I mean, I thought there were mere array (like in C) with fixed size and
> vector or other dynamic containers.

The idea is to allocate only a single block of memory for the fixed-size 
"head" of the struct plus the dynamically-sized "tail," by doing 
something like

   OStoreBTreeNodeData * p = reinterpret_cast<OStoreBTreeNodeData *>(
     new char[
       offsetof(OStoreBTreeNodeData, m_pData) + k * sizeof(T)]);

That trick is used in quite a number of places across the LO codebase, 
the most prominent example being rtl_uString underlying OUString.

> I don't know what you mean by "flexible array member" but above all what
> about if "n" (so  capacityCount()) is 1?
> m_pData[1] would be out of bounds, wouldn't it?

if n is 1, the body of the loop

   for (sal_uInt16 i = 1; i < n; i++)

will be executed zero times, so there would not be any access to 
out-of-bounds m_pData[1].


More information about the LibreOffice mailing list