-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ulog组件空指针与空字符混用的bug #5323
Comments
const char * 就是指针啊 |
没看出有啥毛病 @mysterywolf 看样子被修复过了,可以关了 |
rt_strlen(NULL) 不可以这么使用,会访问 0 地址报错。你进去看看 rt_strlen 源码就能发现了:for 循环中的判断条件是 |
|
rt-thread分支:master
1、ulog_output_to_all_backend函数中若后端不支持颜色或者不是raw,会进入else分支,else中使用使用rt_strlen计算各个输出等级颜色字符串的长度。作者想当然认为color_output_info中存储的是非空字符串,然而color_output_info中是字符串指针,有可能是NULL空指针,而非空字符串,这里误用空指针和空字符串,势必错误。
if (backend->support_color || is_raw)
{
backend->output(backend, level, tag, is_raw, log, size);
}
else
{
/* recalculate the log start address and log size when backend not supported color */
rt_size_t color_info_len = rt_strlen(color_output_info[level]), output_size = size;
if (color_info_len)
{
rt_size_t color_hdr_len = rt_strlen(CSI_START) + color_info_len;
2、ulog_formater中用到color_output_info时,又认为存储的对象是指针.....,向后不一致。
#ifdef ULOG_USING_COLOR
/* add CSI start sign and color info /
if (color_output_info[level])
{
log_len += ulog_strcpy(log_len, log_buf + log_len, CSI_START);
log_len += ulog_strcpy(log_len, log_buf + log_len, color_output_info[level]);
}
#endif / ULOG_USING_COLOR /
3、
#ifdef ULOG_USING_COLOR
/ color output info /
static const char * const color_output_info[] =
{
ULOG_COLOR_ASSERT,
NULL,
NULL,
ULOG_COLOR_ERROR,
ULOG_COLOR_WARN,
NULL,
ULOG_COLOR_INFO,
ULOG_COLOR_DEBUG,
};
#endif / ULOG_USING_COLOR */
4、空指针、空字符串傻傻分不清,还写系统,只能哈哈了。
5、修复很简单,自己搞定。
The text was updated successfully, but these errors were encountered: