From 0b682003ff79d9b74e213fb0d442d29576b7e994 Mon Sep 17 00:00:00 2001 From: Parthiban Nallathambi Date: Fri, 6 Nov 2026 14:51:41 +0530 Subject: [libc][common] Match the picolibc asctime_r and ctime_r prototypes picolibc declares the buffer as char[restrict static 26], so the pointer form warns with -Warray-parameter and the NULL check with -Wnonnull-compare. Other C libraries keep the pointer form. Signed-off-by: Parthiban Nallathambi --- components/libc/compilers/common/ctime.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/components/libc/compilers/common/ctime.c b/components/libc/compilers/common/ctime.c index 77ef7fab34..6ea8aade53 100644 --- a/components/libc/compilers/common/ctime.c +++ b/components/libc/compilers/common/ctime.c @@ -26,6 +26,7 @@ * 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable * 2023-10-23 Shell add lock for _g_timerid * 2023-11-16 Shell Fixup of nanosleep if previous call was interrupted + * 2026-11-06 Parthiban match the picolibc asctime_r/ctime_r prototypes */ #include "sys/time.h" @@ -59,6 +60,15 @@ #define _WARNING_NO_RTC "Cannot find a RTC device!" +/* picolibc declares the buffer as char[restrict static __ASCTIME_SIZE], so it is non-null */ +#if defined(__PICOLIBC__) && defined(__ASCTIME_SIZE) +#define _ASCTIME_BUF(b) b[__restrict_arr __min_size(__ASCTIME_SIZE)] +#define _ASCTIME_BUF_NULL(b) 0 +#else +#define _ASCTIME_BUF(b) *b +#define _ASCTIME_BUF_NULL(b) ((b) == RT_NULL) +#endif + #if defined(RT_USING_SMART) && defined(RT_USING_VDSO) #include #endif @@ -255,9 +265,9 @@ time_t mktime(struct tm * const t) } RTM_EXPORT(mktime); -char* asctime_r(const struct tm *t, char *buf) +char *asctime_r(const struct tm *t, char _ASCTIME_BUF(buf)) { - if(t == RT_NULL || buf == RT_NULL) + if (t == RT_NULL || _ASCTIME_BUF_NULL(buf)) { rt_set_errno(EFAULT); return RT_NULL; @@ -316,7 +326,7 @@ char *asctime(const struct tm *timeptr) } RTM_EXPORT(asctime); -char *ctime_r(const time_t * tim_p, char * result) +char *ctime_r(const time_t *tim_p, char _ASCTIME_BUF(result)) { struct tm tm; return asctime_r(localtime_r(tim_p, &tm), result); -- cgit v1.3.1