strftime.c

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
tatikor_143Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
jkrConnect With a Mentor 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

0
 
tatikor_143Author 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
0
 
waysideCommented:
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.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
tatikor_143Author 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;
        }
0
 
tatikor_143Author Commented:
I am geting error number as 22 and it is referring to invalid argument..

How to resolve this?
0
 
waysideCommented:
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.
0
 
tatikor_143Author 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
0
 
tatikor_143Author Commented:
It happens very rarely..but I need the solution to avoid this..Any help?
0
 
evilrixSenior Software Engineer (Avast)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.
0
 
tatikor_143Author 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..
0
All Courses

From novice to tech pro — start learning today.