Author Topic: Search and Replace Bug [FIXED]  (Read 4564 times)

Offline Edis Krad

  • Single posting newcomer
  • *
  • Posts: 6
Search and Replace Bug [FIXED]
« on: October 18, 2006, 06:58:43 am »
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
« Last Edit: October 19, 2006, 03:04:54 am by Edis Krad »

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Search and Replace Bug
« Reply #1 on: October 18, 2006, 09:06:51 am »
That's funny :).
Thanks for pointing it out.
Be patient!
This bug will be fixed soon...

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5493
Re: Search and Replace Bug
« Reply #2 on: October 18, 2006, 12:50:34 pm »
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;

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;
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;

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



[EDIT 3] will also limit that end to 0 so it does not become negative
« Last Edit: October 18, 2006, 01:33:14 pm by killerbot »

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5493
Re: Search and Replace Bug
« Reply #3 on: October 18, 2006, 01:34:22 pm »
fixed : rev 3101

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

Offline Edis Krad

  • Single posting newcomer
  • *
  • Posts: 6
Re: Search and Replace Bug
« Reply #4 on: October 19, 2006, 03:04:30 am »
Wooot!! Thanks a lot :D