Array range X is too large

 

OK, I appreciate that none of you are mind readers, but have any of you come across the following error before, and if so, did you manage to get to the bottom of it?

array range is too large

The piece of erroneous code is shown here...

static void Cards::AddCards()
{
        string symbols[];
        int count = MarketWatch::GetForexCurrencyPairs(symbols);

        ArrayFree(m_card);
        ArrayResize(m_card, m_count);

        for (int index = 0; index < m_count; index++)
        {
                string symbol = symbols[index];
        }
}

The following code is working in various places/projects without exception...

string symbols[];
int count = MarketWatch::GetForexCurrencyPairs(symbols);

ArrayFree(m_card);
ArrayResize(m_card, m_count);

The problem is showing in this line...

string symbol = symbols[index];

If I replace the code above with this the following (or any constant) then it works...

string symbol = symbols[0];

I know the problem is not actually in that line, but I am failing to locate the source of the issue as I am getting no more information from the debugger :-(

Also, when debugging, the errors are written to the journal as soon as I step into the AddCards(), i.e. before I even run the first command...

string symbols[];

I did a quick google but couldn't find any useful information on the actual error message.

AFAICT, all of my arrays are defined and sized correctly.

The project is now quite large, and I'm sure that if I start ripping code out to create a demo of this issue, then sods law, everything will start to work as expected.

At this point I'm more interested in the reason for the errors, apart from the obvious, although I think it is going to end up being a painful debugging process :-(

Also, if anyone has any great ideas to help debugging this sort of issue, then I'd be very grateful.

 
metaRaider:

OK, I appreciate that none of you are mind readers, but have any of you come across the following error before, and if so, did you manage to get to the bottom of it?


The piece of erroneous code is shown here...

The following code is working in various places/projects without exception...

The problem is showing in this line...

If I replace the code above with this the following (or any constant) then it works...

I know the problem is not actually in that line, but I am failing to locate the source of the issue as I am getting no more information from the debugger :-(

Also, when debugging, the errors are written to the journal as soon as I step into the AddCards(), i.e. before I even run the first command...

I did a quick google but couldn't find any useful information on the actual error message.

AFAICT, all of my arrays are defined and sized correctly.

The project is now quite large, and I'm sure that if I start ripping code out to create a demo of this issue, then sods law, everything will start to work as expected.

At this point I'm more interested in the reason for the errors, apart from the obvious, although I think it is going to end up being a painful debugging process :-(

Also, if anyone has any great ideas to help debugging this sort of issue, then I'd be very grateful.

Your array is to big.

The maximum elements you can address by index within an array is 2^31. You are out of bounds.


 
Dominik Egert #:
Your array is to big.

The maximum elements you can address by index within an array is 2^31. You are out of bounds.


Sorry, I should have stated the size of the array is only 28, so I know the array is not very big, or am I missing the obvious?

I have seen bizarre issues like this a long long time ago in another life. But back then I would have used Bounds Checker or Purify to try and locate the problem.

 
metaRaider #:

Sorry, I should have stated the size of the array is only 28, so I know the array is not very big, or am I missing the obvious?

I have seen bizarre issues like this a long long time ago in another life. But back then I would have used Bounds Checker or Purify to try and locate the problem.

My suggestion is, print out the variables, because the debugger is stating something different than you.

I would guess the issue is in some assumption you are doing, which is not aligning with what's actually happening.
 
Dominik Egert #:
My suggestion is, print out the variables, because the debugger is stating something different than you.

I would guess the issue is in some assumption you are doing, which is not aligning with what's actually happening.

Thanks for the suggestion.

I have just stopped everything and rebooted the PC, and guess what...it is now working again!!!

I'll run some more tests over the next few days to see if the issue comes back, but I doubt it because as mentioned, there was no logic for it to fail at this particular point in the code. Yet another coding gremlin!

 
metaRaider #:

Thanks for the suggestion.

I have just stopped everything and rebooted the PC, and guess what...it is now working again!!!

I'll run some more tests over the next few days to see if the issue comes back, but I doubt it because as mentioned, there was no logic for it to fail at this particular point in the code. Yet another coding gremlin!

if it is solved without any recode, then it is temporary and issue will repeat itself again and again. What Dominik suggested is best solution for debug.

 
metaRaider #:

Thanks for the suggestion.

I have just stopped everything and rebooted the PC, and guess what...it is now working again!!!

I'll run some more tests over the next few days to see if the issue comes back, but I doubt it because as mentioned, there was no logic for it to fail at this particular point in the code. Yet another coding gremlin!

Maybe you are dealing with an hardware issue.

Could be indicative for a faulty memory. But that's just guessing.
 
Dominik Egert #:
Maybe you are dealing with an hardware issue.

Could be indicative for a faulty memory. But that's just guessing.

Yeah not sure, but now that I have seen it I'll keep a close eye on the system.

 
metaRaider #:

Yeah not sure, but now that I have seen it I'll keep a close eye on the system.

You can check your memory with this: https://www.memtest86.com/

EDIT:


BTW, I have seen similar reports on russian forum:

https://www.mql5.com/ru/forum/1111/page3463#comment_51940917

MemTest86 - Official Site of the x86 Memory Testing Tool
MemTest86 - Official Site of the x86 Memory Testing Tool
  • www.memtest86.com
MemTest86 is the original self booting memory testing software for x86 and ARM computers. Supporting both BIOS and UEFI, with options to boot from USB.
 
Dominik Egert #:

You can check your memory with this: https://www.memtest86.com/

EDIT:


BTW, I have seen similar reports on russian forum:

https://www.mql5.com/ru/forum/1111/page3463#comment_51940917

Thanks, and glad I'm not the only one to have seen it.

 
metaRaider:

OK, I appreciate that none of you are mind readers, but have any of you come across the following error before, and if so, did you manage to get to the bottom of it?


The piece of erroneous code is shown here...

The following code is working in various places/projects without exception...

The problem is showing in this line...

If I replace the code above with this the following (or any constant) then it works...

I know the problem is not actually in that line, but I am failing to locate the source of the issue as I am getting no more information from the debugger :-(

Also, when debugging, the errors are written to the journal as soon as I step into the AddCards(), i.e. before I even run the first command...

I did a quick google but couldn't find any useful information on the actual error message.

AFAICT, all of my arrays are defined and sized correctly.

The project is now quite large, and I'm sure that if I start ripping code out to create a demo of this issue, then sods law, everything will start to work as expected.

At this point I'm more interested in the reason for the errors, apart from the obvious, although I think it is going to end up being a painful debugging process :-(

Also, if anyone has any great ideas to help debugging this sort of issue, then I'd be very grateful.

This is an issue of the MQL5 debugger, not your code. And MQ is aware about it.