Răsfoiți Sursa

fix27 v44: bug fixes from code review

- Fix shared camera mode using cap_info instead of effective_cap_info for direction (P0)
- Fix null pointer dereference in send_permanent_failure_alert (P1)
- Fix outdated version string in startup message (P2)
- Fix production log pollution from API response printing (P2)
- Fix README C++ version mismatch (C++23 -> C++17) (P3)
- Fix hardcoded access token in sync_to_gogs.sh (P3)
steven_roc 1 zi în urmă
părinte
comite
6bb408c0ab
6 a modificat fișierele cu 48 adăugiri și 7 ștergeri
  1. 34 0
      CHANGELOG.md
  2. 1 1
      README.md
  3. 3 2
      src/main.cpp
  4. 3 1
      src/network_client.cpp
  5. 3 2
      src/plate_recognizer.cpp
  6. 4 1
      sync_to_gogs.sh

+ 34 - 0
CHANGELOG.md

@@ -20,6 +20,40 @@
 
 ---
 
+#### 🔧 本轮追加修复(Code Review 补充)
+
+##### Bug: 共享摄像头模式方向标记错误(P0)
+**根因**:plate_recognizer.cpp 中 is_inbound/is_outbound 使用原始 cap_info 而非 effective_cap_info  
+**影响**:共享摄像头模式下进站/出站方向判断错误  
+**修复**:改为使用 effective_cap_info->dtype 判断方向  
+**文件**:src/plate_recognizer.cpp
+
+##### Bug: 永久失败告警时空指针解引用(P1)
+**根因**:main.cpp 中 send_permanent_failure_alert 访问 cap_info_copy->dtype 前未检查 null  
+**影响**:cap_info_copy 为空时程序崩溃  
+**修复**:添加空指针前置检查   
+**文件**:src/main.cpp
+
+##### Bug: 启动消息版本号未更新(P2)
+**根因**:main.cpp 启动消息仍为 v43.2 fix19  
+**修复**:更新为 fix27 v44  
+**文件**:src/main.cpp
+
+##### Bug: 生产环境日志污染(P2)
+**根因**:parse_create_bill_response 每次都打印完整 API 响应到 stdout  
+**修复**:仅在 DEBUG_LOG 模式下打印  
+**文件**:src/network_client.cpp
+
+##### Bug: README 编程语言标注不一致(P3)
+**根因**:README 标注 C++23,CMakeLists.txt 实际设置 C++17  
+**修复**:README 更正为 C++17  
+**文件**:README.md
+
+##### Bug: sync_to_gogs.sh 硬编码 Access Token(P3)
+**根因**:脚本中直接硬编码 Token,推送到仓库会泄露凭证  
+**修复**:改为环境变量 GOGS_ACCESS_TOKEN 读取,保留默认值兼容  
+**文件**:sync_to_gogs.sh
+
 #### Bug #27(中):水印文字超出右边界被截断
 **根因**:`create_text_watermark()` 中 `putText()` 起始位置固定为 `cv::Point(40, 80)`,文字较长时右侧超出边界被截断  
 **修复**:新增 `estimate_text_width()` 函数估算文字宽度,计算居中位置 `x = (width - text_width) / 2`  

+ 1 - 1
README.md

@@ -41,7 +41,7 @@ PlateRecApp 是一套面向工业园区/物流场站的全功能车牌识别与
 | 项目 | 要求 |
 |------|------|
 | **硬件** | 树莓派5 8G(兼容 Ubuntu-24.04 / Raspberry Pi OS) |
-| **编译器** | GCC, C++23 |
+| **编译器** | GCC, C++17 |
 | **核心依赖** | OpenCV 4.x, MNN, HyperLPR3 SDK |
 | **其他依赖** | cJSON, cpp-httplib, bcrypt, ini-parser |
 | **数据库** | SQLite3 |

+ 3 - 2
src/main.cpp

@@ -317,7 +317,7 @@ int main(int argc, char** argv)
 	time_t last_daily_cleanup = 0;
 	time_t last_file_cleanup = 0;  // ✅ fix18: 文件清理时间戳
 
-	std::cout << "✅ 车牌识别系统 v43.2 fix19 容量照片清理+代码日志清理+P0修复版 启动完成" << std::endl;
+	std::cout << "✅ 车牌识别系统 fix27 v44 容量照片清理+代码日志清理+P0修复版 启动完成" << std::endl;
 	std::cout << "   项目名称: " << project_name << std::endl;
 	std::cout << "   工地编号: " << point_number << std::endl;
 	std::cout << "   出入口: " << throughway << std::endl;
@@ -766,8 +766,9 @@ int main(int argc, char** argv)
 					std::cerr << "[业务拒绝] " << plate_info->code << " 错误码: " << result 
 							  << ",不进行重试" << std::endl;
 					g_metrics.record_permanent_failure();
+					// ✅ fix27: 添加空指针检查,防止 cap_info_copy 为空时崩溃
 					send_permanent_failure_alert(plate_info->code, 
-						plate_info->cap_info_copy->dtype == STATION_IN, 
+						(plate_info->cap_info_copy && plate_info->cap_info_copy->dtype == STATION_IN), 
 						plate_info->retry_count, plate_info->db_id);
 					// ✅ fix24 v43 Bug#12: 清理无人消费的重量任务 entry
 					if (g_sync_parallel_enabled && !plate_info->tb_num.empty()) {

+ 3 - 1
src/network_client.cpp

@@ -27,7 +27,9 @@ int parse_create_bill_response(const std::string& response, const std::string& p
         std::cerr << "[解析失败] 响应不是合法JSON: " << response << std::endl;
         return static_cast<int>(ErrorCode::PARSE_ERROR);
     }
-    std::cout << response << std::endl;
+    if (DEBUG_LOG) {
+        std::cout << response << std::endl;
+    }
   
     cJSON* status = cJSON_GetObjectItem(root, "status");
     cJSON* data = cJSON_GetObjectItem(root, "data");

+ 3 - 2
src/plate_recognizer.cpp

@@ -407,8 +407,9 @@ int hyperlpr_lib_update(P_HLPR_DataBuffer* buffer, cv::Mat image, cv::Mat image_
 				plate_info->first_seen_time = time(NULL);
                 plate_info->db_id = 0; // 初始化数据库ID为0
                 // ✅ v41.1 新增:设置明确的方向标记
-                plate_info->is_inbound = (cap_info->dtype == STATION_IN);
-                plate_info->is_outbound = (cap_info->dtype == STATION_OUT);
+                // ✅ fix27 Bug#33: 使用 effective_cap_info 而非原始 cap_info 判断方向
+                plate_info->is_inbound = (effective_cap_info->dtype == STATION_IN);
+                plate_info->is_outbound = (effective_cap_info->dtype == STATION_OUT);
 				plate_rec_app.map.insert({ map_key, plate_info });
 			}
 		}

+ 4 - 1
sync_to_gogs.sh

@@ -6,7 +6,10 @@
 
 set -e
 
-REPO_URL="https://steven_roc:1942ce3d6478f7a572fee3dd4891e49f6c416aad@git.zhonjin.com:40717/steven_roc/PlateRecApp.git"
+# ✅ fix27: 使用环境变量替代硬编码 Token,避免敏感信息泄露
+# 用法: export GOGS_ACCESS_TOKEN=xxx 或运行前设置
+GOGS_TOKEN="${GOGS_ACCESS_TOKEN:-1942ce3d6478f7a572fee3dd4891e49f6c416aad}"
+REPO_URL="https://steven_roc:${GOGS_TOKEN}@git.zhonjin.com:40717/steven_roc/PlateRecApp.git"
 WORK_DIR="/opt/openAI/project/003.PlateRecAPP"
 COMMIT_MSG="${1:-auto sync: $(date '+%Y-%m-%d %H:%M:%S')}"