Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2155
  • Last Modified:

Sometime: Debug Assertion Failed expression str!=NULL

Dear Experts,

I have just added a logging function into an existing program. Basically the program does alot of file convertion. It works fine until the logging function built in.

Im getting the error message like this:
-------------------------------
Debug Assertion Failed!

Program: c:\file_extract\file_service.exe
File: fprintf.c
Line: 56

Expression: != NULL

For more information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

(press Retry to debug the application)
----------------------------------------

The biggest problem is, this error message will only occur every 18 hours. this services will run every 2 minutes. when the error message occurs, the environment has no different as compare to 2 minutes before. the logging code:

void writeToZipLog(CString strMsg)
{
      //1) Only print into ZIPLog.txt when the string is NOT NULL
      //2) Print current date and time
      CTime datenow;
      datenow = datenow.GetCurrentTime();
      FILE *streamFile;
      if(!strMsg.IsEmpty()){
            streamFile      = fopen ("SBBZIPLog.txt", "a");
            fprintf (streamFile,"%s | %s\r\n", datenow.Format("%d-%m-%Y %H:%M:%S"), strMsg);
            fclose(streamFile);
      }
}
0
Heliumyap
Asked:
Heliumyap
  • 4
  • 2
1 Solution
 
mahesh1402Commented:
The C runtime library source code comes with VC++, so you can inspect fprintf.c for yourself.  Here's the relevant part:

int __cdecl fprintf (
        FILE *str,
        const char *format,
        ...
        )
/*
 * 'F'ile (stream) 'PRINT', 'F'ormatted
 */
{
        va_list(arglist);
        REG1 FILE *stream;
        REG2 int buffing;
        int retval;
        va_start(arglist, format);

        _ASSERTE(str != NULL);      <-- THIS IS LINE 56
        _ASSERTE(format != NULL);

It would appear that you're passing a NULL pointer as the first argument in a call to fprintf.  

Are you sure that your FILE* was successfully set?  Perhaps your file open or create failed.

Check your file is successfully opened is append mode by using if(streamFile!=NULL)...and also include full path in fopen() while passing file name.

-MAHESH




0
 
HeliumyapAuthor Commented:
I have tripple confirm that no other application is using the file.

i have set the if(streamFile!=NULL)... and if it really happens, write to another file. start from tomorrow morning, i should be able to see if it really happening.

i wish to write it to EvenLog. but in VC++ is just too tedious. btw, do you know any website sharing how VC++ should write to windows evenlog?

-helium-
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
mahesh1402Commented:
Also 'Simple class to fire messages to Windows EventLog'
http://www.codeproject.com/system/CEventLog.asp

and Event Logging section at codeproject
http://www.codeproject.com/system/#Event+Logging

-MAHESH

0
 
HeliumyapAuthor Commented:
Hi Mahesh,

Oh no.. IT is still the same event i have the if(streamFile!=NULL) statement in the code.  

however, i remind this line of code:
streamFile     = fopen ("SBBZIPLog.txt", "a");

This program has been running for more than 6 days before it hit the "Debug Assertion Failed" error.

any more idea?
0
 
mahesh1402Commented:
Have you checked that without using fopen..means using MFC class CFile etc ?

-MAHESH
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now