News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

bug in vector_tpl<T> (patch is included)

Started by wackdone, July 04, 2012, 04:12:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wackdone

Hi all!

There is a bug (a mistake?) in tpl/vector_tpl.h in r5804.


void vector_tpl<T>::store_at(const uint 32 pos, cosnt T& elem)
    ...
    resize((pos & 0xFFFFFFF7) + 8);


No! the right mask value is 0xFFFFFFF8.
(== ((~0) << 3))

example case: size==8 and pos==8,
the method tries to append new entry at the bottom of vector with expansion,
but the 'size' variable doesn't change in current code.

I found it while writing new extension for original Simutrans.
This problem is too tiny (only 4bits inverted in source file) but serious,
and hard to encounter, I think.

patch file attached with this article, is using '#if' directive.
It's no use for applying on main trunk. Just modify only one character.
(Sorry, I had missed in attaching a patch file. The second file has same contents with first one.)

Best Regards.

Dwachs

#1
Thanks for spotting! At all places, where store_at is called, the vector was already appropriately resize()'d. So this error never took effect.

Fixed in 5806. Size is doubled until it fits the index.

Parsley, sage, rosemary, and maggikraut.

wackdone

Thank you for quick respone.
I also checked the use of store_at() by grep'ng source codes.
I saw this problem was coverd by limited usage of this method, as you say.

Thanks for updating repos, too.

IgorEliezer

O wow, nice way to introduce yourself to the community.

And welcome to the community. :D