anuragmenon@gmail.com wrote:
Hello,
Trying to debug a weird problem here. When I run this program many
times over, at some point argc gets corrupted and I get the error that
enough number of arguments are not provided. It definitely seems to
have something to do with the env. variable being set and used because
the previous version of this code did not have that variable and did
not have this problem. I am running this on linux on a powerpc based
hardware. stdlib.h is included.
--
My condition is that if this env variable does not exist at all or if
it exisits and it is set to 1, I want to <D STUFFand if it exisits
and is set to 0, <D NT D STUFF>
--
Here is the relevant portion of the program I am trying to debug. .
--
int main(int argc, char** argv) {
--
char* status = 0;
--
if(argc < 2)
{
fprintf(stderr, " Not enough arguments.\n");
fflush(stderr);
}
--
while(1)
{
--
status = getenv("TIMER_STATUS");
if((status == 0) || ((status != 0) && (atoi(status) != 1)))
{
<Do STUFF>
}
else
{
<D NT STUFF>
--
}
>
>
>
}
--
In MST cases, the program runs just fine. But after about 10-15 times
of running repeatedly, i will always get the error that there are not
enough arguments. If I reboot the entire board that will restart the
kernel and everything, all is well once again until we get into that
restarting many times scenario.
Any ideas of where I might start to debug this?
--
Thanks much,
Vinod
I'd add
#DEBUG
#ifdef DEBUG
int k;
printf("argc=%d\n",argc)
for (k=0;k<argc;k++)
{
printf(" %s",argv[k]);
}
printf ("\n");
#endif
:-)
As a startsince your code seems to check argc before doing anything
nasty, it seems unlikeley you're are crashing the stack