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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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
jkrCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.