Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Search and Replace Bug [FIXED]

(1/1)

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.

killerbot:
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 :


--- Code: ---TRAF_UINT32 x;


--- End code ---
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 :

--- Code: ---                data->start += lengthReplace;
--- End code ---
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 :

--- Code: ---data->start = pos;
--- End code ---

so we get :

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


--- End code ---


[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:
Wooot!! Thanks a lot :D

Navigation

[0] Message Index

Go to full version