Skip to content

Commit 6a12704

Browse files
authored
Merge pull request #2412 from armink/fix_ulog
Update the ulog
2 parents 1cf890c + 5845930 commit 6a12704

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

components/utilities/ulog/ulog.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,10 @@ RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *ta
315315
/* is not in interrupt context */
316316
if (rt_interrupt_get_nest() == 0)
317317
{
318-
log_len += ulog_strcpy(log_len, log_buf + log_len, rt_thread_self()->name);
318+
rt_size_t name_len = rt_strnlen(rt_thread_self()->name, RT_NAME_MAX);
319+
320+
rt_strncpy(log_buf + log_len, rt_thread_self()->name, name_len);
321+
log_len += name_len;
319322
}
320323
else
321324
{

include/rtdbg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#define DBG_COLOR
4343
#endif
4444

45-
#if defined(RT_USING_ULOG) && defined(DBG_ENABLE)
45+
#if defined(RT_USING_ULOG)
4646
/* using ulog compatible with rtdbg */
4747
#include <ulog.h>
4848
#else

include/rtthread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ void *rt_memcpy(void *dest, const void *src, rt_ubase_t n);
516516
rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_ubase_t count);
517517
rt_int32_t rt_strcmp(const char *cs, const char *ct);
518518
rt_size_t rt_strlen(const char *src);
519+
rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen);
519520
char *rt_strdup(const char *s);
520521
#if defined(__CC_ARM) || defined(__CLANG_ARM)
521522
/* leak strdup interface */

src/kservice.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ rt_int32_t rt_strcmp(const char *cs, const char *ct)
461461
return (*cs - *ct);
462462
}
463463
RTM_EXPORT(rt_strcmp);
464+
464465
/**
465466
* The strnlen() function returns the number of characters in the
466467
* string pointed to by s, excluding the terminating null byte ('\0'),
@@ -476,11 +477,13 @@ rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen)
476477
{
477478
const char *sc;
478479

479-
for (sc = s; *sc != '\0' && sc - s < (int)maxlen; ++sc) /* nothing */
480+
for (sc = s; *sc != '\0' && (rt_ubase_t)(sc - s) < maxlen; ++sc) /* nothing */
480481
;
481482

482483
return sc - s;
483484
}
485+
RTM_EXPORT(rt_strnlen);
486+
484487
/**
485488
* This function will return the length of a string, which terminate will
486489
* null character.

0 commit comments

Comments
 (0)