File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
components/libc/compilers/common Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -239,8 +239,28 @@ RTM_EXPORT(mktime);
239239
240240char * asctime_r (const struct tm * t , char * buf )
241241{
242- RT_ASSERT (rt_strlen (days ) > (t -> tm_wday << 2 ));
243- RT_ASSERT (rt_strlen (months ) > (t -> tm_mon << 2 ));
242+ /* Checking input validity */
243+ if (rt_strlen (days ) <= (t -> tm_wday << 2 ) || rt_strlen (months ) <= (t -> tm_mon << 2 ))
244+ {
245+ LOG_W ("The input 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+ }
244264
245265 /* "Wed Jun 30 21:49:08 1993\n" */
246266 * (int * ) buf = * (int * ) (days + (t -> tm_wday << 2 ));
You can’t perform that action at this time.
0 commit comments