Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 12-18-2004, 04:54 PM   #1
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"));

char pathname[1024];
if (!strcmp(httpGET_PATH, "")) {
		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);
		setenv("HTTPPATH", pathname, 0);
Old 12-18-2004, 05:53 PM   #2
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.


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

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

All times are GMT -5. The time now is 03:14 PM.

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