LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-18-2004, 03:54 PM   #1
Scrag
Member
 
Registered: Mar 2004
Location: Wisconsin
Distribution: Kali Linux
Posts: 122

Rep: Reputation: 15
This causes my program to crash/hang in C...


This code casues my program to crash in C. Its compiles without any errors or warnings. Does anyone know why, or how I can fix this? The two lines of code will both cause program to hang/crash.

pathname = getenv("HTTPPATH");
strcpy(pathname, getenv("HTTPPATH"));

Code:
char pathname[1024];
.
.
.
if (!strcmp(httpGET_PATH, "")) {
		chdir(pathname);
		count = scandir(pathname, &files, 0, alphasort);
		setenv("HTTPPATH", pathname, 0);
	}
	else {
		pathname = getenv("HTTPPATH");  //CAUSES progrma to CRASH. 
                //strcpy(pathname, getenv("HTTPPATH"));  //Also causes to CRASH
		strcat(pathname, "/");
		strcat(pathname, httpGET_PATH);
		count = scandir(pathname, &files, 0, alphasort);
		chdir(pathname);
		setenv("HTTPPATH", pathname, 0);
	}
THANKS
 
Old 12-18-2004, 04:53 PM   #2
bm17
Member
 
Registered: Sep 2004
Location: Santa Cruz, CA, USA
Distribution: Redhat 9.0
Posts: 104

Rep: Reputation: 15
I don't know what C compiler you are using but it is sad that it doesn't issue a warning about assigning the results of getenv() to a char array. The second attempt (via strcpy()) is better, but you are not checking the return value of getenv(). It might be zero. I suggest that you call getenv("HTTPPATH") first, validate and printout the return value, and then strcpy it into pathname.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick Tips for LINUX CRASH/HANG thandermax Linux - Newbie 3 06-25-2005 01:24 PM
Program crash data..? RoaCh Of DisCor Mandriva 2 03-20-2005 10:04 PM
Mozilla Firefox 0.8rc/Gnome Crash/Hang problem imposter Debian 2 06-16-2004 02:04 AM
How could a program crash between 2 printf() 's? paul76 Programming 12 09-11-2003 12:17 PM
Free a used port after program crash Dek Linux - Networking 10 05-01-2003 09:20 AM


All times are GMT -5. The time now is 08:05 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration