Skip to content

fix: [log] verbosity configuration initialization order#404

Closed
add-uos wants to merge 0 commit into
linuxdeepin:release/eaglefrom
add-uos:release/eagle
Closed

fix: [log] verbosity configuration initialization order#404
add-uos wants to merge 0 commit into
linuxdeepin:release/eaglefrom
add-uos:release/eagle

Conversation

@add-uos

@add-uos add-uos commented Oct 13, 2025

Copy link
Copy Markdown
Contributor
  • Added verbosity field to config structure for persistent storage
  • Fixed initialization sequence to load verbosity from config before updating options
  • Ensured debug level is set from saved configuration rather than default options
  • Maintained configuration file compatibility with new verbosity parameter

Log: Fix debug level configuration loading sequence

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @add-uos, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我对这段代码进行了审查,以下是我的分析和改进建议:

  1. 语法逻辑方面:
  • 代码整体语法正确,但存在一些格式不一致的问题,比如有些缩进使用空格,有些使用制表符。建议统一使用空格进行缩进。
  • 在LPF_V4L2.c中,config_update()的调用顺序调整是合理的,先加载配置,再更新,最后使用配置。
  1. 代码质量方面:
  • 新增的verbosity功能与现有代码风格保持一致,遵循了项目的编码规范。
  • 注释风格统一,使用了#作为注释符号。
  • 建议在config_update()函数中verbosity的检查条件中添加最大值限制,例如:
if(my_options->verbosity >= 0 && my_options->verbosity <= 3)  // 假设最大值为3
    my_config->verbosity = my_options->verbosity;
  1. 代码性能方面:
  • 使用strdup()分配内存,记得在适当时候释放,避免内存泄漏。
  • config_load()函数中每次都要重新解析文件,可以考虑添加配置缓存机制,但考虑到配置文件可能需要动态更新,当前实现也是合理的。
  1. 代码安全方面:
  • 在config_load()中使用strtoul()转换字符串为整数是安全的,但建议添加错误处理:
else if(strcmp(token, "verbosity") == 0)
{
    char *endptr;
    long val = strtol(value, &endptr, 10);
    if (endptr == value || *endptr != '\0') {
        // 处理转换错误
        fprintf(stderr, "Invalid verbosity value\n");
        continue;
    }
    my_config.verbosity = (int)val;
}
  1. 其他建议:
  • 建议在cameraconfig.h中为verbosity添加注释,说明其用途和有效范围:
int verbosity; /* Debug verbosity level (0=none, 1=normal, 2=detailed, 3=verbose) */
  • 考虑将verbosity的有效范围定义为枚举或宏,提高代码可读性:
#define VERBOSITY_NONE    0
#define VERBOSITY_NORMAL  1
#define VERBOSITY_DETAILED 2
#define VERBOSITY_VERBOSE 3

总体而言,这次改动添加了verbosity功能,实现了配置的保存和加载,逻辑清晰。但需要注意边界条件的处理和代码安全性。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants