No one knows what the values of those variables you're using are. We don't know when, where, and how those functions are called, or what context they're called in, etc..

Runtime errors involving memory handling requires us to have the code, compile it ourselves, and run it with the data that you're using. Otherwise, the only thing that anyone can tell you is to check your indices and memory overwrites.

Regards,

Paul McKenzie