File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
components/libc/compilers/common Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change 2929#include <rtdevice.h>
3030#endif
3131
32- #define DBG_TAG "TIME "
32+ #define DBG_TAG "time "
3333#define DBG_LVL DBG_INFO
3434#include <rtdbg.h>
3535
@@ -239,6 +239,29 @@ RTM_EXPORT(mktime);
239239
240240char * asctime_r (const struct tm * t , char * buf )
241241{
242+ /* Checking input validity */
243+ if (rt_strlen (days ) <= (t -> tm_wday << 2 ) || rt_strlen (months ) <= (t -> tm_mon << 2 ))
244+ {
245+ LOG_W ("asctime_r: the input parameters exceeded the limit, please check it." );
246+ * (int * ) buf = * (int * ) days ;
247+ * (int * ) (buf + 4 ) = * (int * ) months ;
248+ num2str (buf + 8 , t -> tm_mday );
249+ if (buf [8 ] == '0' )
250+ buf [8 ] = ' ' ;
251+ buf [10 ] = ' ' ;
252+ num2str (buf + 11 , t -> tm_hour );
253+ buf [13 ] = ':' ;
254+ num2str (buf + 14 , t -> tm_min );
255+ buf [16 ] = ':' ;
256+ num2str (buf + 17 , t -> tm_sec );
257+ buf [19 ] = ' ' ;
258+ num2str (buf + 20 , 2000 / 100 );
259+ num2str (buf + 22 , 2000 % 100 );
260+ buf [24 ] = '\n' ;
261+ buf [25 ] = '\0' ;
262+ return buf ;
263+ }
264+
242265 /* "Wed Jun 30 21:49:08 1993\n" */
243266 * (int * ) buf = * (int * ) (days + (t -> tm_wday << 2 ));
244267 * (int * ) (buf + 4 ) = * (int * ) (months + (t -> tm_mon << 2 ));
You can’t perform that action at this time.
0 commit comments