Bug in CQueue

 
  1. int CQueue::CopyTo(T &dst_array[],const int dst_start=0)
      {
    //--- resize array
       if((dst_start+m_size)>ArraySize(dst_array))
          if(ArrayResize(dst_array,dst_start+m_size)<0)
             return(0);
    //--- copy queue elements from head to tail
       if(m_tail>=m_head)
          return(ArrayCopy(dst_array,m_array,dst_start,m_head,m_size));
    //--- copy queue elements from head to end
      // int num_copied=ArrayCopy(dst_array,m_array,dst_start,m_head,m_size-m_head);
      // this line has a bug, it assumes m_array size is equal to m_size
      // should be replaced with the following line
     int num_copied=ArrayCopy(dst_array,m_array,dst_start,m_head,ArraySize(m_array)-m_head);
    
    //--- copy queue elements from beginning to tail
       num_copied+=ArrayCopy(dst_array,m_array,dst_start+num_copied,0,m_tail);
    //--- return number of copied elements
       return(num_copied);
      }
    Hi,
    I encountered a bug in CQueue, not sure how to report it.  The underline code is not correct.
 
williamwong:
  1. Hi,
    I encountered a bug in CQueue, not sure how to report it.  The underline code is not correct.

You are right, I confirm it and your solution.

Please note this other one too :

https://www.mql5.com/en/forum/442040

[Suspected bug] CQueue::CopyTo error
[Suspected bug] CQueue::CopyTo error
  • 2023.02.19
  • pperea21
  • www.mql5.com
Hi, I've found that CopyTo method has a mistake Original code is : When CQueue is full it returns less elements than it actually has: Error is in C...
 
Alain Verleyen #:

You are right, I confirm it and your solution.

Please note this other one too :

https://www.mql5.com/en/forum/442040

How to inform metaquotes to make changes to the library? Seems like no one is maintaining mql5 anymore.
 
williamwong #:
How to inform metaquotes to make changes to the library? Seems like no one is maintaining mql5 anymore.
They are informed.
 
Alain Verleyen #:
They are informed.

thank you.

 

Thank you all

Fixed

template<typename T>
int CQueue::CopyTo(T &dst_array[],const int dst_start=0)
  {
//--- resize array
   if((dst_start+m_size)>ArraySize(dst_array))
      if(ArrayResize(dst_array,dst_start+m_size)<0)
         return(0);
//--- copy queue elements from head to tail
   if(m_tail>m_head)
      return(ArrayCopy(dst_array,m_array,dst_start,m_head,m_size));
//--- copy queue elements from head to end
   int num_copied=ArrayCopy(dst_array,m_array,dst_start,m_head,m_array.Size()-m_head);
//--- copy queue elements from beginning to tail
   num_copied+=ArrayCopy(dst_array,m_array,dst_start+num_copied,0,m_tail);
//--- return number of copied elements
   return(num_copied);
  }