Skip to content

Commit 5c50a87

Browse files
authored
Merge pull request #4458 from mysterywolf/time
[libc][time] 修复没有末尾\0的bug
2 parents 0da4317 + cc1277d commit 5c50a87

File tree

1 file changed

+3
-1
lines changed
  • components/libc/compilers/common

1 file changed

+3
-1
lines changed

components/libc/compilers/common/time.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* 2012-12-08 Bernard <clock_time.c> fix the issue of _timevalue.tv_usec initialization,
1717
* which found by Rob <rdent@iinet.net.au>
1818
* 2021-02-12 Meco Man move all of the functions located in <clock_time.c> to this file
19+
* 2021-03-15 Meco Man fixed bug: https://club.rt-thread.org/ask/question/423650.html
1920
*/
2021

2122
#include <sys/time.h>
@@ -152,13 +153,14 @@ char* asctime_r(const struct tm *t, char *buf)
152153
num2str(buf + 20, (t->tm_year + 1900) / 100);
153154
num2str(buf + 22, (t->tm_year + 1900) % 100);
154155
buf[24] = '\n';
156+
buf[25] = '\0';
155157
return buf;
156158
}
157159
RTM_EXPORT(asctime_r);
158160

159161
char* asctime(const struct tm *timeptr)
160162
{
161-
static char buf[25];
163+
static char buf[26];
162164
return asctime_r(timeptr, buf);
163165
}
164166
RTM_EXPORT(asctime);

0 commit comments

Comments
 (0)