[MT4] CString: critical bug!

 

UPDATE: Bug also affects Remove(), Replace(), Left(), and Insert(). Updated attached file.


When using the Remove method to remove any substring with a position of 0, the Remove method enters an endless loop the results in an out of memory critical error. The issue stems from the difference in the StringSubstr() function between the MT4 and MT5 platform. On Mt5, StringSubstr("hello World",0,0) returns an empty string, while on MT4 the same function returns a copy of the whole string.

Example script to demonstrate bug:

#property strict
#include <Strings\String.mqh>   

void OnStart()
{
   CString bug;   
   bug.Assign("1 Hello World");  
   bug.Remove("1");
   Print(bug.Str());  
}

Here is a quick fix and replacement file for CString on MT4. Update: fixed other methods as well

//+------------------------------------------------------------------+
//| Remove all occurrences of the substring                          |
//+------------------------------------------------------------------+
uint CString::Remove(const string substring)
  {
   int    result=0,len,pos=-1;
   string tmp;
//---
   len=StringLen(substring);
   while((pos=StringFind(m_string,substring,pos))>=0)
     {
      //tmp=StringSubstr(m_string,0,pos);
      tmp= pos == 0 ? "" : StringSubstr(m_string,0,pos);
      m_string=tmp+StringSubstr(m_string,pos+len);
      result++;
     }
//--- result
   return(result);
  }
Files:
String.mqh  14 kb
 
nicholishen:

When using the Remove method to remove any string with a position of 0, the Remove method enters an endless loop the results in an out of memory critical error. The issue stems from the difference in the StringSubstr() function between the MT4 and MT5 platform. On Mt5, StringSubstr("hello World",0,0) returns an empty string, while on MT4 the same function returns a copy of the whole string.

Example script to demonstrate bug:

Here is a quick fix and replacement file for CString on MT4.


Report this to the Service Desk, if you didn't already. 

 
Drazen Penic:

Report this to the Service Desk, if you didn't already. 


Done, but since they are no longer supporting MQL4 standard library (many bugs in CIndicators they refuse to address) I figured I share it here as well.

 

It might have saved you some time by reading post #2 before you jumped on your high-horse to issue me a citation from the MQL neighborhood watch. And didn't we already establish that this is a metaquotes dba MQL5 Ltd forum?

 

updated OP with new file to fix the other methods.

 
nicholishen: It might have saved you some time by reading post #2 before you jumped on your high-horse
If you look at the time stamps, there is two minutes difference in our posts. Your second post did not exist when I was replying to your original post and #1.
 
whroeder1:
If you look at the time stamps, there is two minutes difference in our posts. You post did not exist when I was replying.
So you spent more than two minutes on that? Why? Do you feel that strongly that the community shouldn't know about a critical bug?
 
nicholishen:

Done, but since they are no longer supporting MQL4 standard library (many bugs in CIndicators they refuse to address) I figured I share it here as well.

Who said that ?

Thanks for sharing.

 
Alain Verleyen:

Who said that ?

Thanks for sharing.

Metaquotes service desk.

In response to bug filed for CiATR; won't even compile....

Hello.

Thank you very much, but, unfortunately, we do not have plans to change something.

Best regards,

Support team

 
nicholishen:
Metaquotes service desk.

In response to bug filed for CiATR; won't even compile....

Hello.

Thank you very much, but, unfortunately, we do not have plans to change something.

Best regards,

Support team

Good to know, thanks.
Reason: