UI 代码纳入规范检查:大括号 K&R 化、strcpy 换 memcpy 等违规修复

- pre-commit 配置:移除 Drivers/BSP/UI/ 整目录排除,14 个 UI 源文件全部受 cppcheck + 规范检查
- ui_net_sink.c:11 处 Allman 大括号归并 K&R,i/c 声明改即用
- ui_port.c:7 处大括号归并
- ui_net_sink_backend_mcu.c:2 处大括号归并
- ui_menu_view.c:menu_frame_t 指针改 const
- ui_page_net_cfg.c:6 处 strcpy 改 memcpy

验证:pre-commit 全钩子通过、模拟器 0 警、菜单/内容页像素回归 PASS、Keil 0 错 0 警
This commit is contained in:
2026-09-13 19:38:14 +08:00
parent cb8cea38b2
commit 34528a9798
6 changed files with 36 additions and 53 deletions
+1 -2
View File
@@ -57,11 +57,11 @@ repos:
language: system
types: [c]
# 仅扫描项目自有代码;排除第三方库与 LVGL 依赖文件
# (UI 生成文件 ui_font_cn_12/ui_menu_tab 由生成器按工程约定产出,纳入受检)
exclude: |
(?x)^(
Drivers/CMSIS/|
Drivers/STM32F4xx_HAL_Driver/|
Drivers/BSP/UI/|
Drivers/BSP/NET/lftpd/|
Drivers/BSP/dhara/|
Lib/|
@@ -85,7 +85,6 @@ repos:
(?x)^(
Drivers/CMSIS/|
Drivers/STM32F4xx_HAL_Driver/|
Drivers/BSP/UI/|
Drivers/BSP/NET/lftpd/|
Drivers/BSP/GD5F2GQ5UE/nand_ftl\.|
Drivers/BSP/dhara/|
+1 -1
View File
@@ -477,7 +477,7 @@ void ui_menu_view_frame_destroy(uint8_t depth) {
* 函数说明:只改选中数据 + 跟随滚动、重绘框体,不重建对象
*/
void ui_menu_view_frame_refresh(uint8_t depth, uint8_t sel) {
menu_frame_t *f = &s_frame[depth];
const menu_frame_t *f = &s_frame[depth];
/* 未建或越界直接返回 */
if (!f->built || depth >= MENU_PAGE_MAX || sel >= f->item_cnt) {
+13 -26
View File
@@ -54,8 +54,7 @@ static uint32_t g_gen; /* 建立监听时的网络代次号(变化
* 限定条件:无
* 函数说明:对全部数据字节做异或累加(协议约定的简单校验);len 为 0 时返回 0
*/
static uint8_t remo_crc(const uint8_t *d, int len)
{
static uint8_t remo_crc(const uint8_t *d, int len) {
int i;
uint8_t c = 0;
@@ -72,8 +71,7 @@ static uint8_t remo_crc(const uint8_t *d, int len)
* 限定条件:p 指向至少 2 字节可写空间
* 函数说明:网络协议多字节字段统一采用大端序传输
*/
static void put_u16(uint8_t *p, uint16_t v)
{
static void put_u16(uint8_t *p, uint16_t v) {
p[0] = (uint8_t)(v >> 8);
p[1] = (uint8_t)(v & 0xFF);
}
@@ -85,8 +83,7 @@ static void put_u16(uint8_t *p, uint16_t v)
* 限定条件:p 指向至少 4 字节可写空间
* 函数说明:网络协议多字节字段统一采用大端序传输
*/
static void put_u32(uint8_t *p, uint32_t v)
{
static void put_u32(uint8_t *p, uint32_t v) {
p[0] = (uint8_t)(v >> 24);
p[1] = (uint8_t)(v >> 16);
p[2] = (uint8_t)(v >> 8);
@@ -101,8 +98,7 @@ static void put_u32(uint8_t *p, uint32_t v)
* 函数说明:帧格式 [TAG_DEVICE][CMD][LEN_H][LEN_LO][DATA][CRC];CRC 为 payload 异或;
* 无连接时直接返回
*/
static void remo_send(uint8_t cmd, const uint8_t *data, uint16_t len)
{
static void remo_send(uint8_t cmd, const uint8_t *data, uint16_t len) {
uint8_t *p;
if (g_client < 0) {
@@ -128,8 +124,7 @@ static void remo_send(uint8_t cmd, const uint8_t *data, uint16_t len)
* 限定条件:g_client >= 0
* 函数说明:payload 为 [宽u16][高u16][缓冲字节数u32],共 6 字节(大端)
*/
static void remo_send_init(void)
{
static void remo_send_init(void) {
uint8_t init[8];
put_u16(init, UI_W);
@@ -158,8 +153,7 @@ static void remo_send_init(void)
* 位图后回送 [偏移u32][位图 3200B],非 0 偏移暂不支持
* 3. 未知命令码静默丢弃
*/
static void remo_handle(const uint8_t *f, int n)
{
static void remo_handle(const uint8_t *f, int n) {
uint8_t tag;
uint8_t cmd;
uint16_t len;
@@ -270,8 +264,7 @@ static rm_parser_t g_rm; /* 全局解析器:状态跨 poll 调用保持(
* 限定条件:无
* 函数说明:新建连接、连接断开或长度越界失步时调用,清除半帧残留
*/
static void rm_parser_reset(void)
{
static void rm_parser_reset(void) {
g_rm.st = RM_ST_TAG;
g_rm.pos = 0;
g_rm.plen = 0;
@@ -288,8 +281,7 @@ static void rm_parser_reset(void)
* 3. payload 长度越界(>RM_MAX_RX_PAYLOAD)判为损坏并复位
* 4. 整帧 CRC 通过才回调 remo_handle;状态跨多次 recv 保持
*/
static void rm_parser_feed(uint8_t b)
{
static void rm_parser_feed(uint8_t b) {
switch (g_rm.st) {
case RM_ST_TAG:
if (b != TAG_CLIENT) {
@@ -351,8 +343,7 @@ static void rm_parser_feed(uint8_t b)
* 限定条件:net_* 网络子系统可用
* 函数说明:绑定 g_port 与任意本地地址并进入监听;成功后写回 g_listen
*/
static int bind_listen(void)
{
static int bind_listen(void) {
int ls;
struct net_sockaddr_in addr;
@@ -386,8 +377,7 @@ static int bind_listen(void)
* 限定条件:网络子系统已初始化(模拟器端 Winsock 已就绪)
* 函数说明:创建流式 Socket 并绑定端口进入监听;成功才记录网络代次号
*/
int ui_net_sink_start(uint16_t port)
{
int ui_net_sink_start(uint16_t port) {
g_port = port;
if (bind_listen() < 0) {
@@ -413,11 +403,8 @@ int ui_net_sink_start(uint16_t port)
* 5. 对端关闭/真错误时关闭客户端;若监听 Socket 随客户端失效
* (MCU 单连接模型)则重建监听,等待重连
*/
void ui_net_sink_poll(void)
{
void ui_net_sink_poll(void) {
int n;
int i;
int c;
/* 网络重建(代次变化):旧监听/客户端已随芯片复位失效,重建监听 */
if (net_get_generation() != g_gen) {
@@ -442,7 +429,7 @@ void ui_net_sink_poll(void)
/* 无客户端时尝试接受连接 */
if (g_client < 0) {
c = net_accept(g_listen, NULL, NULL);
int c = net_accept(g_listen, NULL, NULL);
if (c >= 0) {
g_client = c;
rm_parser_reset();
@@ -453,7 +440,7 @@ void ui_net_sink_poll(void)
/* 有客户端时非阻塞收帧,逐字节喂入解析状态机 */
n = net_recv(g_client, g_rx, (int)sizeof(g_rx), NET_MSG_DONTWAIT);
if (n > 0) {
for (i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
rm_parser_feed((uint8_t)g_rx[i]);
}
} else if (n == 0) {
+2 -4
View File
@@ -22,8 +22,7 @@
* 限定条件:ui_port_init() 已成功
* 函数说明:帧缓冲本就是 1bpp(布局与协议一致),直接整帧拷贝
*/
int ui_net_sink_get_lcdmem(uint8_t *out, uint32_t out_size)
{
int ui_net_sink_get_lcdmem(uint8_t *out, uint32_t out_size) {
const uint8_t *fb;
if (out == NULL || out_size < UI_NET_SINK_MONO_SIZE) {
@@ -46,7 +45,6 @@ int ui_net_sink_get_lcdmem(uint8_t *out, uint32_t out_size)
* 限定条件:无
* 函数说明:缓存后由 keypad 读取回调在下次轮询上报(键码映射在 ui_port 内完成)
*/
void ui_net_sink_inject_key(uint8_t remo_key)
{
void ui_net_sink_inject_key(uint8_t remo_key) {
ui_port_queue_key(remo_key);
}
+12 -6
View File
@@ -127,24 +127,30 @@ static void nc_refresh(uint16_t row, char *name, char *value) {
switch (row) {
case 0u:
(void)strcpy(name, "IP地址");
(void)memcpy(name, "IP地址", sizeof("IP地址"));
net_cfg_fmt_ipv4(cfg->ip, value, NC_ROW_BUF_LEN);
break;
case 1u:
(void)strcpy(name, "子网掩码");
(void)memcpy(name, "子网掩码", sizeof("子网掩码"));
net_cfg_fmt_ipv4(cfg->mask, value, NC_ROW_BUF_LEN);
break;
case 2u:
(void)strcpy(name, "默认网关");
(void)memcpy(name, "默认网关", sizeof("默认网关"));
net_cfg_fmt_ipv4(cfg->gw, value, NC_ROW_BUF_LEN);
break;
case 3u:
(void)strcpy(name, "MAC地址");
(void)memcpy(name, "MAC地址", sizeof("MAC地址"));
nc_fmt_value(row, value);
break;
case 4u:
(void)strcpy(name, "保存");
(void)strcpy(value, (s_saved == 0u) ? "ENTER" : ((s_saved == 1u) ? "OK" : "ERR"));
(void)memcpy(name, "保存", sizeof("保存"));
if (s_saved == 0u) {
(void)memcpy(value, "ENTER", sizeof("ENTER"));
} else if (s_saved == 1u) {
(void)memcpy(value, "OK", sizeof("OK"));
} else {
(void)memcpy(value, "ERR", sizeof("ERR"));
}
break;
default:
break;
+7 -14
View File
@@ -28,8 +28,7 @@ static volatile uint8_t g_pending_key = 0;
* 限定条件:无
* 函数说明:仅映射方向/确认/返回等导航键,其余返回 0 表示忽略
*/
static uint8_t ui_map_key(uint8_t remo_key)
{
static uint8_t ui_map_key(uint8_t remo_key) {
switch (remo_key) {
case UI_KEY_UP: return (uint8_t)LV_KEY_UP;
case UI_KEY_DOWN: return (uint8_t)LV_KEY_DOWN;
@@ -51,8 +50,7 @@ static uint8_t ui_map_key(uint8_t remo_key)
* 函数说明:1. 若有缓存键则上报 PRESSED 并清除缓存
* 2. 否则上报 RELEASED,等待下次按键
*/
static void ui_keypad_read(lv_indev_t * indev, lv_indev_data_t * data)
{
static void ui_keypad_read(lv_indev_t * indev, lv_indev_data_t * data) {
(void)indev;
if (g_pending_key != 0) {
data->state = LV_INDEV_STATE_PRESSED;
@@ -74,8 +72,7 @@ static void ui_keypad_read(lv_indev_t * indev, lv_indev_data_t * data)
* 限定条件:ui_port_init() 已成功调用
* 函数说明:整帧拷贝到 g_ui_fbuf,供 RemoDispBus 推送至远端
*/
static void ui_flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * color_p)
{
static void ui_flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * color_p) {
(void)disp;
(void)area;
memcpy(g_ui_fbuf, color_p, UI_FB_SIZE);
@@ -91,8 +88,7 @@ static void ui_flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * c
* 2. 创建 keypad 设备及默认输入组,绑定刷新回调
* 3. 后续须周期调用 ui_port_step 驱动刷新
*/
int ui_port_init(void)
{
int ui_port_init(void) {
lv_init();
static lv_display_t *disp = NULL;
@@ -127,8 +123,7 @@ int ui_port_init(void)
* 限定条件:ui_port_init() 已成功调用
* 函数说明:缓冲由 flush 回调更新,供网络推流读取
*/
uint8_t *ui_port_get_framebuffer(void)
{
uint8_t *ui_port_get_framebuffer(void) {
return g_ui_fbuf;
}
@@ -139,8 +134,7 @@ uint8_t *ui_port_get_framebuffer(void)
* 限定条件:无
* 函数说明:映射后缓存,由 keypad 回调在下次轮询上报
*/
void ui_port_queue_key(uint8_t remo_key)
{
void ui_port_queue_key(uint8_t remo_key) {
uint8_t k = ui_map_key(remo_key);
if (k != 0) {
g_pending_key = k;
@@ -154,8 +148,7 @@ void ui_port_queue_key(uint8_t remo_key)
* 限定条件:ui_port_init() 已成功调用
* 函数说明:依次调用 lv_tick_inc 与 lv_timer_handler,须由任务周期调用
*/
void ui_port_step(uint32_t tick_ms)
{
void ui_port_step(uint32_t tick_ms) {
lv_tick_inc(tick_ms);
lv_timer_handler();
}