jewee
asked on
getenv Crashes!
I noticed that when i use getenv to get a particular environment variable, the program crashes...
However, i wanted the environemnt variables to be optional. So, if the env variables are not set, then use the default ones.
But when it's not defined, ...it shuts down.
However, i wanted the environemnt variables to be optional. So, if the env variables are not set, then use the default ones.
But when it's not defined, ...it shuts down.
What OS and what compiler are you using?
I had a similar problem like this using GNU compiler on SunOS.
The problem was some where else in the code, but it would currupt the memory so that it would crash when calling getenv.
I had a similar problem like this using GNU compiler on SunOS.
The problem was some where else in the code, but it would currupt the memory so that it would crash when calling getenv.
ASKER
I call the getEnvVar method in the constructor...
bool ViewForm::getEnvVar()
{
serverHostName = getenv("SERVER_HOSTNAME");
if (serverHostName == NULL)
{
printf("Error\n");
return false;
}
}
I am running on a SunOS
bool ViewForm::getEnvVar()
{
serverHostName = getenv("SERVER_HOSTNAME");
if (serverHostName == NULL)
{
printf("Error\n");
return false;
}
}
I am running on a SunOS
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is your constructor being called before entry into the main() function?
serverHostName is going to point to read-only memory. You don't do anything like accidentally free/deleting it or writing to it do you?
Please post the relevant part of the code so that we can go further.
Cheers!