We help IT Professionals succeed at work.

strftime.c

tatikor_143
tatikor_143 asked
on
Hi ,

I am getting this error...

Debug Assertion Failed..
File : strftime.c


Expression ((timeptr ->tm_mday>=1)&&( timeptr->tm_mday<=31)

I included time.h header file and the lines of code that use above library function is

_gmtime32_s(&theTime, &(pReport->timeStamp));
      strftime(timeString,  sizeof(timeString), "%d/%m/%Y %H:%M:%S", &theTime);

If we can resolve this error...then the application may work fine..

Thanks
Comment
Watch Question

Author

Commented:
This question is linked with
http://www.experts-exchange.com/Programming/Languages/CPP/Q_22910991.html

I am able to convert few records but it is throwing error after converting few records and it is aborting..

Please help me out in this..

Thaks

Commented:
I assume theTime is a struct tm?

Can you verify in the debugger that the value of  theTime.tm_mday is between 1 and 31 before calling the function?

I think you are getting an assertion because the value for tm_mday is outside the legal range.

Author

Commented:
Thanks for the quick response..
>>>  assume theTime is a struct tm?
---Yes it is..

Can you verify in the debugger that the value of  theTime.tm_mday is between 1 and 31 before calling the function?

--case('d'):              /* mday in decimal (01-31) */
            /* pass alternate_form as the no leading zeros flag */
        {
            _VALIDATE_RETURN( ( ( timeptr->tm_mday >=1 ) && ( timeptr->tm_mday <= 31 ) ), EINVAL, FALSE)
            _store_num(timeptr->tm_mday, 2, string, left,
                       alternate_form);
            break;
        }

Author

Commented:
I am geting error number as 22 and it is referring to invalid argument..

How to resolve this?

Commented:
The macro:  _VALIDATE_RETURN checks that the tm_mday parameter is within the legal range of 1-31. Since you got an assertion, your value is not in the legal range.

You need to find where in your code you are setting the value to the incorrect  value.

Author

Commented:
I am reading from a binary file ..I just convert it with the data I receive..

Is there any workaround..and the frequency of this error is 1 out of 100 records.

Thanks

Author

Commented:
It happens very rarely..but I need the solution to avoid this..Any help?
CERTIFIED EXPERT
Top Expert 2012
Commented:
Validate the 'struct tm' value using 'mktime()' before calling that function, e.g.


_gmtime32_s(&theTime, &(pReport->timeStamp));
 
if (-1 != mktime(&theTime)) {
 
  strftime(timeString,  sizeof(timeString), "%d/%m/%Y %H:%M:%S", &theTime);
 
else {
 
  // error - skip record or react accordingly
}

Open in new window

evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

Commented:
Are you able to post a full code example that errors so I can look at it? There isn't enough to go on at the moment.

Author

Commented:
Thanks jkr for some work around....

Now..its skipping few records and converting the remaining records thereby avoiding the aseertion from strftime.c function ..

Now I am able to convert for the remaing records avoiding the problametic ones.

Thanks and I am closing this thread..