Program terminates before completion with no event, crash or stackdump

This is a discussion on Program terminates before completion with no event, crash or stackdump within the Windows Programming forums, part of the Platform Specific Boards category; Greetings, I have a windows C program problem that has me baffled. The section of the code in question is ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    15

    Program terminates before completion with no event, crash or stackdump

    Greetings,

    I have a windows C program problem that has me baffled. The section of the code in question is doing a recursive loop to search through a directory structure. The program (on one machine) doesn't complete. There is nothing in the event logs and no crash file or stackdump.

    I added a print statement to see where it might be failing. The last entry in the log file is not even a complete entry.

    Here' the snippet of code:
    Code:
    		
    // if this is a directory, call comp_files recursively, 
    // unless it is a Junction point, which we don't want to recurse		
    if ( S_ISDIR(fileStat.st_mode) )
    {
    	if (S_ISLNK(fileStat.st_mode)) //if junction point, continue to next entry
    	{
    		continue;
    	}
    	else
    	{
    		sprintf(nextSrcDirCyg, "%s%s", srcDirCyg, shadDirEntry->d_name);
    		sprintf(nextShadDirCyg, "%s%s", shadDirCyg, shadDirEntry->d_name);
    		strcat(nextSrcDirCyg,"/");
    		strcat(nextShadDirCyg,"/");
    		//recursively call comp_files with new directory name
    		comp_files(nextSrcDirCyg, nextShadDirCyg);
    		sprintf(logstring, "returning from recursive call for directory %s", nextShadDirCyg);
    logprint(logstring);
    fflush(locallogfile);
    	}
    }
    Here are the last few lines from the log. Note that the last line of the log is not even complete in spite of a fflush to the log.

    Mon Nov 4 20:35:25 2013 returning from recursive call for directory /cygdrive/G/apteryx/pats/THALBOB_3976/
    Mon Nov 4 20:35:25 2013 returning from recursive call for directory /cygdrive/G/apteryx/pats/TIMMESYDNEY_6648/
    Mon Nov 4 20:35:25 2013 returning from recursive call for directory /cygdrive/G/apteryx/pats/TRAMPEBETTYA_5371/
    Mon Nov 4 20:35:25 2013 returni

    Any suggestions on how to diagnose this will be greatly appreciated.
    Leon

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,672
    > sprintf(nextSrcDirCyg, "%s%s", srcDirCyg, shadDirEntry->d_name);
    > sprintf(nextShadDirCyg, "%s%s", shadDirCyg, shadDirEntry->d_name);
    How big are these buffers?

    > logprint(logstring);
    What is the prototype for this function?

    If it's a printf style function with varargs, then this will screw you up if you happen to have filenames with % characters in them.

    NEVER pass raw strings to printf-style functions!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    15
    buffers are 500 characters
    Code:
    	char nextSrcDirCyg[500];
    	char nextShadDirCyg[500];
    Logprint is very simple...
    Code:
    int logprint(char *print_str)
    {
    
    	lt = time(NULL);
    	now = localtime(&lt);
    	strcpy(asciiTime, asctime(now));
    	strlength = strlen(asciiTime);
    	asciiTime[strlength -1] = '\0';
    	fprintf(log_file, "%s   %s\n", asciiTime, print_str);
    	return(0);
    }

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,672
    > logprint(logstring);
    > fflush(locallogfile);
    What's the difference between locallogfile and the log_file in the function you just posted?

    setvbuf - C++ Reference
    Consider doing this right after you open your log file, and passing _IONBF to make your log file unbuffered to begin with.
    Then you don't have to keep remembering to do fflush()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program prematurely terminates?
    By ScottieK in forum C Programming
    Replies: 1
    Last Post: 03-26-2012, 01:20 AM
  2. Is memory released after program terminates?
    By dbergman in forum C++ Programming
    Replies: 3
    Last Post: 06-09-2010, 11:42 AM
  3. program terminates abruptly
    By roaan in forum C Programming
    Replies: 3
    Last Post: 08-28-2009, 03:53 PM
  4. Storing objects after program terminates
    By ejohns85 in forum C++ Programming
    Replies: 7
    Last Post: 08-25-2009, 06:27 AM
  5. this program just starts and terminates
    By s2theG in forum C Programming
    Replies: 2
    Last Post: 07-17-2005, 03:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21