diff options
| author | liukangcc <[email protected]> | 2021-09-27 14:18:54 +0800 |
|---|---|---|
| committer | liukangcc <[email protected]> | 2021-09-27 14:26:06 +0800 |
| commit | 169b09004ee9ed15c1e8cb15c7d2fe3042895f29 (patch) | |
| tree | c27873da9d8daf34e26a75ac9e07847217b576fd /components | |
| parent | c447018c406f1a49000150d8a52224b576eea65a (diff) | |
[update] asctime_r return value.
Diffstat (limited to 'components')
| -rw-r--r-- | components/libc/compilers/common/time.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index efcfe4dec0..840629f973 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -239,8 +239,28 @@ RTM_EXPORT(mktime); char* asctime_r(const struct tm *t, char *buf) { - RT_ASSERT(rt_strlen(days) > (t->tm_wday << 2)); - RT_ASSERT(rt_strlen(months) > (t->tm_mon << 2)); + /* Checking input validity */ + if (rt_strlen(days) <= (t->tm_wday << 2) || rt_strlen(months) <= (t->tm_mon << 2)) + { + LOG_W("The input exceeded the limit, please check it."); + *(int*) buf = *(int*) days; + *(int*) (buf + 4) = *(int*) months; + num2str(buf + 8, t->tm_mday); + if (buf[8] == '0') + buf[8] = ' '; + buf[10] = ' '; + num2str(buf + 11, t->tm_hour); + buf[13] = ':'; + num2str(buf + 14, t->tm_min); + buf[16] = ':'; + num2str(buf + 17, t->tm_sec); + buf[19] = ' '; + num2str(buf + 20, 2000 / 100); + num2str(buf + 22, 2000 % 100); + buf[24] = '\n'; + buf[25] = '\0'; + return buf; + } /* "Wed Jun 30 21:49:08 1993\n" */ *(int*) buf = *(int*) (days + (t->tm_wday << 2)); |
