Page 1 of 1

RTC v.1 Driver Error in KEIL and IAR

Posted: Thu Oct 22, 2015 6:10 am
by alexblack
Hello.
In current trunk there is error in RTC v.1 driver:

Code: Select all

...
128 static void rtc_decode(uint32_t tv_sec,
129                        uint32_t tv_msec,
130                        RTCDateTime *timespec) {
131   struct tm tim;
132   struct tm *t;
133
134   /* If the conversion is successful the function returns a pointer
135      to the object the result was written into.*/
136 #if defined __GNUC__
137   t = localtime_r((time_t *)&(tv_sec), &tim);
138   osalDbgAssert(t != NULL, "conversion failed");
139 #else
140   struct tm *t = localtime(&tv_sec);
141   memcpy(&timp, t, sizeof(struct tm));
142 #endif
143
144   rtcConvertStructTmToDateTime(&tim, tv_msec, timespec);
145 }
...

When no __GNUC__ defined, in line 140 there is double definition of struct tm *t and in line 141 used variable "timp", but must be tim!
And another note: in KEIL there is function localtime_r.

Re: RTC v.1 Driver Error in KEIL and IAR

Posted: Thu Oct 22, 2015 8:22 am
by Giovanni
Thanks, I will make the required changes.

Giovanni

Re: RTC v.1 Driver Error in KEIL and IAR

Posted: Fri Oct 23, 2015 9:07 am
by Giovanni
I committed a fix, thanks for finding. Bug #650.

Giovanni

Re: RTC v.1 Driver Error in KEIL and IAR

Posted: Tue Oct 27, 2015 2:00 pm
by alexblack
It seems the errors are not solved completely.
First: double definition of struct tm *t is still.
Second: Perhaps must include "time.h" in order to call memcpy? IAR do warning on this.
And one another question: Why You using not thread safe function localtime here?