diff options
| author | guozhanxin <[email protected]> | 2021-03-31 13:59:58 +0800 |
|---|---|---|
| committer | guozhanxin <[email protected]> | 2021-03-31 14:00:09 +0800 |
| commit | d49cc6452406d70ce7a2e2acce786fbe697673b9 (patch) | |
| tree | ddb998772a7915a57ab93b8b52953c99259c3696 /components/libc | |
| parent | f9be3c80e3631ebfc1ecc3e1f1d2df21277c0608 (diff) | |
| parent | 61be3180f57bcb58a7a62acb67e3179934d500b8 (diff) | |
Merge remote-tracking branch 'remotes/origin/master' into add_error_check
Diffstat (limited to 'components/libc')
| -rw-r--r-- | components/libc/compilers/common/time.c | 9 | ||||
| -rw-r--r-- | components/libc/pthreads/pthread.c | 21 |
2 files changed, 28 insertions, 2 deletions
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 083ae9be6c..83b6ed5672 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -21,10 +21,15 @@ #include <sys/time.h> #include <rtthread.h> + #ifdef RT_USING_DEVICE #include <rtdevice.h> #endif +#define DBG_TAG "TIME" +#define DBG_LVL DBG_INFO +#include <rtdbg.h> + /* seconds per day */ #define SPD 24*60*60 @@ -219,6 +224,7 @@ RT_WEAK time_t time(time_t *t) if(time_now == (time_t)-1) { + LOG_W("Cannot find a RTC device to provide time!"); errno = ENOSYS; } @@ -246,12 +252,13 @@ int stime(const time_t *t) } else { + LOG_W("Cannot find a RTC device to provide time!"); errno = ENOSYS; return -1; } return 0; - #else + LOG_W("Cannot find a RTC device to provide time!"); errno = ENOSYS; return -1; #endif /* RT_USING_RTC */ diff --git a/components/libc/pthreads/pthread.c b/components/libc/pthreads/pthread.c index 8a728c4e99..79104d1fd5 100644 --- a/components/libc/pthreads/pthread.c +++ b/components/libc/pthreads/pthread.c @@ -209,6 +209,8 @@ int pthread_create(pthread_t *pid, /* get pthread data */ ptd = _pthread_get_data(pth_id); + RT_ASSERT(ptd != RT_NULL); + if (attr != RT_NULL) { ptd->attr = *attr; @@ -299,6 +301,12 @@ int pthread_detach(pthread_t thread) { int ret = 0; _pthread_data_t *ptd = _pthread_get_data(thread); + if (ptd == RT_NULL) + { + /* invalid pthread id */ + ret = EINVAL; + goto __exit; + } rt_enter_critical(); if (ptd->attr.detachstate == PTHREAD_CREATE_DETACHED) @@ -360,6 +368,12 @@ int pthread_join(pthread_t thread, void **value_ptr) rt_err_t result; ptd = _pthread_get_data(thread); + + if (ptd == RT_NULL) + { + return EINVAL; /* invalid pthread id */ + } + if (ptd && ptd->tid == rt_thread_self()) { /* join self */ @@ -367,7 +381,9 @@ int pthread_join(pthread_t thread, void **value_ptr) } if (ptd->attr.detachstate == PTHREAD_CREATE_DETACHED) + { return EINVAL; /* join on a detached pthread */ + } result = rt_sem_take(ptd->joinable_sem, RT_WAITING_FOREVER); if (result == RT_EOK) @@ -662,7 +678,10 @@ int pthread_cancel(pthread_t thread) /* get posix thread data */ ptd = _pthread_get_data(thread); - RT_ASSERT(ptd != RT_NULL); + if (ptd == RT_NULL) + { + return EINVAL; + } /* cancel self */ if (ptd->tid == rt_thread_self()) |
