Variable gets corrupted

I have this static variable that gets corrupted without my knowledge.

My program has a structure like this

#class static
#memmap xmem

long variable1;
long variable2;

#use “xxx.lib”

int variable3;
int variable4
char variable5
char variable6[10]

function1()
{
auto int variable7;
}
function2()
{
int variable8;
}
function3()
{
variable1=variable1+1
}

main()
{
variable1=0;
while(1)
{
function3();
}
}

somehow variable1 after a while gets corrupted.

Can anyone help me on my problem?

Thanks

I suggest you check your array does not go out of bounds and overwrite un-intended data areas.

The problem probably occurs in function 3 which needs checking/debugging, especially with regards to how you arrive at the final value for variable1. Also check that ‘long’ is correct and/or big enough to hold the result of your calculations. Also it is probably better to try variable1=Another_Variable+1;