Browse Source

Merge pull request #2412 from armink/fix_ulog

Update the ulog
Bernard Xiong 6 years ago
parent
commit
6a12704bc6
4 changed files with 10 additions and 3 deletions
  1. 4 1
      components/utilities/ulog/ulog.c
  2. 1 1
      include/rtdbg.h
  3. 1 0
      include/rtthread.h
  4. 4 1
      src/kservice.c

+ 4 - 1
components/utilities/ulog/ulog.c

@@ -315,7 +315,10 @@ RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *ta
         /* is not in interrupt context */
         /* is not in interrupt context */
         if (rt_interrupt_get_nest() == 0)
         if (rt_interrupt_get_nest() == 0)
         {
         {
-            log_len += ulog_strcpy(log_len, log_buf + log_len, rt_thread_self()->name);
+            rt_size_t name_len = rt_strnlen(rt_thread_self()->name, RT_NAME_MAX);
+
+            rt_strncpy(log_buf + log_len, rt_thread_self()->name, name_len);
+            log_len += name_len;
         }
         }
         else
         else
         {
         {

+ 1 - 1
include/rtdbg.h

@@ -42,7 +42,7 @@
 #define DBG_COLOR
 #define DBG_COLOR
 #endif
 #endif
 
 
-#if defined(RT_USING_ULOG) && defined(DBG_ENABLE)
+#if defined(RT_USING_ULOG)
 /* using ulog compatible with rtdbg  */
 /* using ulog compatible with rtdbg  */
 #include <ulog.h>
 #include <ulog.h>
 #else
 #else

+ 1 - 0
include/rtthread.h

@@ -516,6 +516,7 @@ void *rt_memcpy(void *dest, const void *src, rt_ubase_t n);
 rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_ubase_t count);
 rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_ubase_t count);
 rt_int32_t rt_strcmp(const char *cs, const char *ct);
 rt_int32_t rt_strcmp(const char *cs, const char *ct);
 rt_size_t rt_strlen(const char *src);
 rt_size_t rt_strlen(const char *src);
+rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen);
 char *rt_strdup(const char *s);
 char *rt_strdup(const char *s);
 #if defined(__CC_ARM) || defined(__CLANG_ARM)
 #if defined(__CC_ARM) || defined(__CLANG_ARM)
 /* leak strdup interface */
 /* leak strdup interface */

+ 4 - 1
src/kservice.c

@@ -461,6 +461,7 @@ rt_int32_t rt_strcmp(const char *cs, const char *ct)
     return (*cs - *ct);
     return (*cs - *ct);
 }
 }
 RTM_EXPORT(rt_strcmp);
 RTM_EXPORT(rt_strcmp);
+
 /**
 /**
  * The  strnlen()  function  returns the number of characters in the
  * The  strnlen()  function  returns the number of characters in the
  * string pointed to by s, excluding the terminating null byte ('\0'),
  * 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)
 {
 {
     const char *sc;
     const char *sc;
 
 
-    for (sc = s; *sc != '\0' && sc - s < (int)maxlen; ++sc) /* nothing */
+    for (sc = s; *sc != '\0' && (rt_ubase_t)(sc - s) < maxlen; ++sc) /* nothing */
         ;
         ;
 
 
     return sc - s;
     return sc - s;
 }
 }
+RTM_EXPORT(rt_strnlen);
+
 /**
 /**
  * This function will return the length of a string, which terminate will
  * This function will return the length of a string, which terminate will
  * null character.
  * null character.