[vbox-dev] Fix for nocrt vector implementation

Martin Fleisz martin.fleisz at thincast.com
Tue Dec 20 10:08:49 GMT 2022


Hi Andreas,

I had a closer look at the disassembly and realized that the old
implementation of end() should work just fine.
The issue I experienced had a different reason - as it seems the vector
implementation is lacking a proper assignment operator and only does
shallow copies.
This wrecked my heap and left the impression that the code was trying to
de-reference m_paItems in end() causing a crash.

After eliminating all vector copies the code works just fine - also with
the &m_paItems[m_cItems] implementation. Might be a good idea to delete
or private the assignment operator though while it is not implemented in
the vector template.

Sorry for the noise!

Best regards, Martin

On 16.12.2022 09:42, Martin Fleisz via vbox-dev wrote:
> Hi Andreas,
>
> thanks! I have found another bug and have attached a fix for it.
> The problem is that if you call end() on an empty vector the current
> implementation tries to de-reference a NULL pointer and crashes.
>
> I'm submitting this patch under the MIT license.
>
> Best regards and have a nice weekend,
>
> Martin Fleisz
> Thincast Technologies GmbH
>
>
> diff --git include/iprt/nocrt/vector include/iprt/nocrt/vector
> index 607a75097d3..bbb1acd9de3 100644
> --- include/iprt/nocrt/vector
> +++ include/iprt/nocrt/vector
> @@ -259,17 +259,17 @@ namespace std
>  
>          iterator end() RT_NOEXCEPT
>          {
> -            return iterator(&m_paItems[m_cItems]);
> +            return iterator(m_paItems + m_cItems);
>          }
>  
>          const_iterator end() const RT_NOEXCEPT
>          {
> -            return const_iterator(&m_paItems[m_cItems]);
> +            return const_iterator(m_paItems + m_cItems);
>          }
>  
>          const_iterator cend() const RT_NOEXCEPT
>          {
> -            return const_iterator(&m_paItems[m_cItems]);
> +            return const_iterator(m_paItems + m_cItems);
>          }
>          /** @} */
>  
>
>
> On 15.12.2022 14:39, Andreas Löffler wrote:
>> Hello Martin,
>>
>> thanks for reporting this and for the fix! I'll take care of it.
>>
>>

-- 
Martin Fleisz, Development Manager

Thincast Technologies GmbH              Tel: +43-720-699 844-70
Bahnhofplatz 7/3                        Fax:   +43-2236-328 311
2340 Moedling, Austria                  http://www.thincast.com




More information about the vbox-dev mailing list