Standard library bug in CArrayString::Save(...)

 

Hi,

I think I've found a bug in CArrayString::Save, please see the attached script.

You'll notice that only the first string added in the array is saved, loaded and printed. However, after the modification below in MQL5\Include\Arrays\ArrayString.mqh (highlighted), the script works correctly:

Could you, please, verify?

Thanks in advance. 

 

bool CArrayString::Save(const int file_handle)

  {

   int i=0,len;

//--- check

   if(!CArray::Save(file_handle))

      return(false);

//--- write array length

   if(FileWriteInteger(file_handle,m_data_total,INT_VALUE)!=INT_VALUE)

      return(false);

//--- write array

   for(i=0;i<m_data_total;i++)

     {

      len=StringLen(m_data[i]);

      //--- write string length

      if(FileWriteInteger(file_handle,len,INT_VALUE)!=INT_VALUE)

         return(false);

      //--- write string

      if(len!=0) if(FileWriteString(file_handle,m_data[i],len)!=len*2)

         break;

     }

//--- result

   return(i==m_data_total);

  }
 

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

 
DouglasRechia:

Hi,

I think I've found a bug in CArrayString::Save, please see the attached script.

You'll notice that only the first string added in the array is saved, loaded and printed. However, after the modification below in MQL5\Include\Arrays\ArrayString.mqh (highlighted), the script works correctly:

Could you, please, verify?

Thanks in advance. 

 

You are right, there is a bug. However your fix is also a bug, the FileWriteInteger() returns the number of bytes written, so depending of the file type (ANSI vs UNICODE), both the original code and your fix can be wrong.

Please report this issue to the ServiceDesk.

An other time, don't create topic on this section "Articles, Library comments...", rather use General or Experts Advisors section.

 
angevoyageur:

You are right, there is a bug. However your fix is also a bug, the FileWriteInteger() returns the number of bytes written, so depending of the file type (ANSI vs UNICODE), both the original code and your fix can be wrong.

Please report this issue to the ServiceDesk.

An other time, don't create topic on this section "Articles, Library comments...", rather use General or Experts Advisors section.

 

Thanks for your prompt response and suggestions on how to report bugs. I have just submitted this issue to Service Desk.

Regards,

Douglas 

 

Hi everybody,

I submitted this very same bug through Service Desk on 2014.10.28, but I got no answer so far. Is there any other way to address this issue?

As a temporary solution, I fixed the problem in my local machine. The problem is that everytime the auto update runs, my fix in ArrayString.mqh is reverted.

Thanks in advance,

Douglas

 
DouglasRechia:

Hi everybody,

I submitted this very same bug through Service Desk on 2014.10.28, but I got no answer so far. Is there any other way to address this issue?

As a temporary solution, I fixed the problem in my local machine. The problem is that everytime the auto update runs, my fix in ArrayString.mqh is reverted.

Thanks in advance,

Douglas

They have their own priorities.

To implement your fix you need to define your own class, not modify directly a file of the Standard Library.

#include <Arrays\ArrayString.mqh>
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class CMyArrayString : public CArrayString
  {
public:
                     CMyArrayString(void) { };
                    ~CMyArrayString(void) { };
   virtual bool      CMyArrayString::Save(const int file_handle);

  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool CMyArrayString::Save(const int file_handle)

  {

//--- Add here your own fix

  }
 

And of course you have to use CMyArrayString instead of CArrayString in your script.
Documentation on MQL5: Standard Library
Documentation on MQL5: Standard Library
  • www.mql5.com
Standard Library - Reference on algorithmic/automated trading language for MetaTrader 5
 
angevoyageur:

They have their own priorities.

To implement your fix you need to define your own class, not modify directly a file of the Standard Library.


And of course you have to use CMyArrayString instead of CArrayString in your script.


Here is my fix (see the attached files).

The drawback is that I have to replace every occurrence of CArrayString with CArrayStringFix in my mqh and mq5 files. I believe this should not be the definite solution, but it works.

I hope the desktop guys solve this issue as soon as possible.

Thank you very much

Reason: