String corruption in mql4

 

Hi,

Yesterday I encountered weird string corruption, which I narrowed down to the following code:

Fh=begin_head + Fh;

Fh was more than 1000 ascii chars long, begin_head was maybe 50 chars. After this code, the resulting string was ok, but on the end contained appended part of the original string.

After changing the code to:

Fh=begin_head + "" + Fh;

the result was ok without any corruption. I had the code in 5 places in my EA (with different Fh content, same begin_head content) and all behave incorrectly.

Is the any difference how MT4 interprets those 2 string concatenations? Why adding empty string helped to prevent the corruption and why it happened in the first place? Is this some known issue?

 
marki555: Fh was more than 1000 ascii chars long, begin_head was maybe 50 chars.
  1. Strings are not ASCII, they are 16 bit Unicode.
  2. I concur, there is a problem. The 1000 character string gets truncated around 700. Adding the +""+ makes no difference.
  3. #property strict
    void OnStart(){
       {
       string Fh         = "12345";
       string begin_head = "ABCD";
       Fh = begin_head + Fh;
       PrintFormat("<%s>", Fh);   // <ABCD12345>
       }
       {
       string Fh         = "BEG:";
       for(int i=1; i < 100; ++i)   Fh = Fh + StringFormat(" 234567 %2i", i);
       Fh = Fh + ":END";
       PrintFormat("<%s...%s>", StringSubstr(Fh,0, 30), 
                                StringSubstr(Fh,StringLen(Fh) - 30) );
    // <BEG: 234567  1 234567  2 23456...567 97 234567 98 234567 99:END>
       string begin_head = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
       Fh = begin_head + Fh;
       PrintFormat("<%s...%s>", StringSubstr(Fh,0, 30), 
                                StringSubstr(Fh,StringLen(Fh) - 30) );
    // <ABCDEFGHIJKLMNOPQRSTUVWXYZabcd... 234567 60 234567 61 234567 62>
    // String trimmed
       }
       {
       string Fh         = "BEG:";
       for(int i=1; i < 100; ++i)   Fh = Fh + StringFormat(" 234567 %2i", i);
       Fh = Fh + ":END";
       PrintFormat("<%s...%s>", StringSubstr(Fh,0, 30), 
                                StringSubstr(Fh,StringLen(Fh) - 30) );
    // <BEG: 234567  1 234567  2 23456...567 97 234567 98 234567 99:END>
       string begin_head = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
       Fh = begin_head + "" + Fh;
       PrintFormat("<%s...%s>", StringSubstr(Fh,0, 30), 
                                StringSubstr(Fh,StringLen(Fh) - 30) );
    // <abcdefghijklmnopqrstuvwxyzABCD... 234567 60 234567 61 234567 62>
    // String trimmed
       }
    }
    
  4. Ticket #1590494 created.
  5. Use
       Fh = StringConcatenate(begin_head, Fh);
    // <ABCDEFGHIJKLMNOPQRSTUVWXYZabcd...567 97 234567 98 234567 99:END>
    

 

That bug with strings is there since build 970. I reported it @2016.06.08 11:02, #1488604

Problem description

... when concatenating long strings with the + (plus) operator the resulting string is not properly ended, and a few (cca 50) invalid buffer characters are appended. 

 
Can these bugreports be viewed somewhere? Or are they at least mentioned in some changelog when they are fixed?
 
No and no
 
Marki: Or are they at least mentioned in some changelog when they are fixed?

Previously reported 2016.06.08 11:02, #1488604

I reported 2016.10.19 15:39, #1590494

Support Team 2016.10.20 07:52
Thank you for your message. Fixed. Please wait for updates.
 
whroeder1:

Previously reported 2016.06.08 11:02, #1488604

I reported 2016.10.19 15:39, #1590494

Support Team 2016.10.20 07:52
Thank you for your message. Fixed. Please wait for updates.
Nice, but the last 1012 build was released on August 22, and that bad guy promised no more updates for MT4, so the fix might have virtual meaning.
 
Ovo Cz that bad guy promised no more updates for MT4, so the fix might have virtual meaning.

Where do you get that idea?

So finally. We do not ex­pect to see any de­vel­op­ments to come out of MT4 ever again - MQL5.community traders' Forum just has peoples opinion, nothing from Metaquotes.

And even if MT4 is not going to have any new developments, doesn't mean it won't have bug fixes.

 
whroeder1:

Where do you get that idea?

So finally. We do not ex­pect to see any de­vel­op­ments to come out of MT4 ever again - MQL5.community traders' Forum just has peoples opinion, nothing from Metaquotes.

And even if MT4 is not going to have any new developments, doesn't mean it won't have bug fixes.

True, that was only a joke. I thought it was obvious.
Reason: