News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Search and Replace Bug [FIXED]

Started by Edis Krad, October 18, 2006, 06:58:43 AM

Previous topic - Next topic

Edis Krad

I found a little bug while using the Search & Replace tool.

Suppose you have the text:

ABC_???

Where ??? can be any string. And you want to replace to

XYZ_ABC_???

Basically 'add' XYZ_ to the previous string. So to replace it, I tell the Editor: replace "ABC_" with "XYZ_ABC_" and uncheck ''Whole Word". Orgin is "Entire Scope" and Direction is set to "Up". The result is:

1st replace: XYZ_ABC_??? (good!!)
2nd replace: XYZ_XYZ_ABC_??? (oops!)
3rd replace: XYZ_XYZ_XYZ_ABC_??? (uh oh..)
....

just for the fun of it, I tried again and hit 'replace all', leaving Code::Blocks in an endless loop, replacing the same string over and over again.

This happened with Code::Blocks Version 1.0 revision 3099 (2006-10-17 17:44:03) gcc 3.4.5 Windows/unicode

mandrav

That's funny :).
Thanks for pointing it out.
Be patient!
This bug will be fixed soon...

killerbot

#2
it only fails when the replace it going upwards, probably the new replace position is not set correctly (in this case should be before the word and not after), jumping into the code ....

[EDIT] first observations on the following test code :


TRAF_UINT32 x;


replacing TRAF_ by MY_TRAF_

-> after the first replace end gets changed in the correct direction but as : 0 ==> -=diff aka -=3 --> -3
and then we do in a new loop :
        pos = control->FindText(data->start, data->end, data->findText, flags, &lengthFound);  (8,-3, ..)
and this gives as pos : 3 .. and we're off ;-)

==> first (jumping to) conclusion : wxScintilla does not notice it's an illegal value and 'should' (?) return -1 so we now there's a wrap around, or we should cover that ourself

[EDIT2] :
first error in our code , when replacing :
                data->start += lengthReplace;
should only be done when going down and no up, this causes us to be just after our replacement in this test case.
We should stay in front of the position where the text was found (pos), which just before became the new start position :
data->start = pos;

so we get :

if (data->directionDown)
{
  data->start += lengthReplace
}




[EDIT 3] will also limit that end to 0 so it does not become negative

killerbot

fixed : rev 3101

feel free to play around with it some more ;-)

Edis Krad