I'm not new to programming but I'm definitely new to C-style programming with manual memory management. So I was having this weird problem that I would love to be able to understand. I have - sort of - solved it already, but I don't understand why my solution works, and that bothers me.

The program is somewhat large for an arduino sketch, about 14k, and I was getting all sorts of really strange behavior - which made me suspect that there was some sort of memory issue somewhere - some address that being written to that shouldn't be written to or something like that.

After many hours of frustration and desperately trying to find the problem, I finally tracked it down to this array:

long fingers[6][8];

Increasing the outer dimension of this by 1 fixed the problem, like so:

long fingers[6][9];

The thing is though, I can't find anywhere in my code where I'm calling on or assigning any number above fingers

[7]! So I do not understand at all why adding an extra slot to that array fixes my problems. I've seen at a couple of places that character arrays should be terminated by a null byte, so you should always add an extra char to those above from what you need for your text, but is this the case even with long-type arrays? Or what could possibly be going on here?

Yes, exactly, and this is, as I understand it, the only thing which could cause a problem here - if I try to assign or read from an index above what is actually allocated, but I'm simply not doing that anywhere in my code! I've allocated an array of 8 units, and I'm not referencing anything above index number 7 at any point. That's why I'm so puzzled that this array somehow causes corruption in my code unless I assign an extra slot for it - an extra slot that I never use.

Oh well, I just thought that maybe there was some sort of common newbie mistake I might be doing here that I wasn't aware of, but apparently not, thanks anyway.

Not really... it's kind of a long story. I had some other problems earlier with communicating between arduinos and at the time it seemed like one of the problems I had was that sending a byte like 0x00 would not register as a sent byte on the other end, so instead of counting from 0 I switched to counting from 1 to get around this. In hindsight that probably wasn't the real problem I was having at the time, but anyway I just kept it like that to keep from screwing things up by changing it back to starting from 0 (I had bigger problems to deal with). I know there's a lot of stuff like that which could really be done a lot neater/better, but at the time, fixing things like that seemed a bit like giving the car a new shiny wax coat while both the engine and transmission were broken...