[fixed]irrString Bug in remove function

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

[fixed]irrString Bug in remove function

Post by Ulf »

If you call the string::remove(const string<T,TAlloc> toRemove) function with an empty string it gets stuck in an infinite loop.

It just needs a test for empty string.

Code: Select all

if ( size == 0 )
    return;

Code: Select all

void remove(const string<T,TAlloc> toRemove)
{
	u32 size = toRemove.size();
	if ( size == 0 )
		return;

	u32 pos = 0;
	u32 found = 0;
	for (u32 i=0; i<used; ++i)
	{
		u32 j = 0;
		while (j < size)
		{
			if (array[i + j] != toRemove[j])
				break;
			++j;
		}
		if (j == size)
		{
			found += size;
			i += size - 1;
			continue;
		}

		array[pos++] = array[i];
	}
	used -= found;
	array[used] = 0;
}
This part does it

Code: Select all

i += size - 1; 
size == 0 so it keeps subtracting 1 from i and then adding 1 to i for the loop increment.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Thanks for reporting. I've fixed it and will check-in in a few minutes.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply