From 1b662b1f3111249683c34e4faa6e922a5a7af4da Mon Sep 17 00:00:00 2001 From: ypc <15051963820@163.com> Date: Wed, 8 Jul 2026 13:40:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=8F=91=E7=8E=B0=E7=9A=84=205=20=E4=B8=AA=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=20bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - libfunc: func_cal_crc16/crc32 空数据返回初始值(0xFFFF/0xFFFFFFFF)而非0 - libfunc: func_str2time_sys 年份字段减去1900(适配7-bit位域) - libfunc: func_proc_pid_by_name path[128]→[384] 修复snprintf截断警告 - libtask: task_msg_queue_recv 返回实际消息长度而非固定0 - libxml: myXml_new_child 调用 InsertEndChild 将新元素挂到父节点 - libcmd: cmd_sub_complete 无空格时以完整buf为前缀(修复ncomp=0) 所有修改均通过对应单元测试验证。 --- src/public/libcmd/src/myCmd.cpp | 13 ++++++------- src/public/libfunc/src/myFunc.c | 14 ++++++++------ src/public/libtask/src/myTask.c | 3 ++- src/public/libxml/src/myXml.cpp | 10 +++++++++- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/public/libcmd/src/myCmd.cpp b/src/public/libcmd/src/myCmd.cpp index 83788bb..bd9d17e 100644 --- a/src/public/libcmd/src/myCmd.cpp +++ b/src/public/libcmd/src/myCmd.cpp @@ -140,15 +140,14 @@ void cmd_sub_complete(const char *buf, char ***completions, int *ncomp, { const char *prefix = strrchr(buf, ' '); - if (!prefix) + if (prefix) { - *ncomp = 0; - *completions = NULL; - - return; + prefix++; + } + else + { + prefix = buf; } - - prefix++; int cnt = 0; char **c = NULL; diff --git a/src/public/libfunc/src/myFunc.c b/src/public/libfunc/src/myFunc.c index 52fe113..1bd5ef5 100644 --- a/src/public/libfunc/src/myFunc.c +++ b/src/public/libfunc/src/myFunc.c @@ -107,12 +107,13 @@ uint16_t func_cal_sum_word(const uint8_t *d, uint32_t n) uint16_t func_cal_crc16(const uint8_t *d, uint32_t n) { - if (!d || !n) + if (!n) { - return 0; + return 0xFFFF; } uint16_t crc = 0xFFFF; + for (uint32_t i = 0; i < n; i++) { crc = (crc >> 8) ^ _crc16_tab[(uint8_t)(crc ^ d[i])]; @@ -123,12 +124,13 @@ uint16_t func_cal_crc16(const uint8_t *d, uint32_t n) uint32_t func_cal_crc32(const uint8_t *d, uint32_t n) { - if (!d || !n) + if (!n) { - return 0; + return 0xFFFFFFFF; } uint32_t crc = 0xFFFFFFFF; + for (uint32_t i = 0; i < n; i++) { crc = (crc >> 8) ^ _crc32_tab[(uint8_t)(crc ^ d[i])]; @@ -456,7 +458,7 @@ int func_str2time_sys(const char *s, stru_time_sys *t) return -1; } - t->year = y; + t->year = y - 1900; t->month = mo; t->day = d; t->hour = h; @@ -960,7 +962,7 @@ int func_proc_pid_by_name(const char *name) continue; } char comm[64]; - char path[128]; + char path[384]; snprintf(path, sizeof(path), "/proc/%s/comm", e->d_name); FILE *fp = fopen(path, "r"); if (!fp) diff --git a/src/public/libtask/src/myTask.c b/src/public/libtask/src/myTask.c index a42f4bf..ed3ee72 100644 --- a/src/public/libtask/src/myTask.c +++ b/src/public/libtask/src/myTask.c @@ -740,9 +740,10 @@ int task_msg_queue_recv(stru_task_msg_queue_t p_queue, void *msg, p->head = (p->head + 1) % p->max_msgs; p->msg_count--; + pthread_cond_signal(&p->cond); pthread_mutex_unlock(&p->lock); - return 0; + return (int)msg_len; } /** diff --git a/src/public/libxml/src/myXml.cpp b/src/public/libxml/src/myXml.cpp index a5cc4e3..aa501c4 100644 --- a/src/public/libxml/src/myXml.cpp +++ b/src/public/libxml/src/myXml.cpp @@ -131,8 +131,16 @@ myXmlElem_t myXml_new_child(myXmlElem_t parent, const char *name) } tinyxml2::XMLDocument *doc = ((tinyxml2::XMLElement *)parent)->GetDocument(); + tinyxml2::XMLElement *el = doc->NewElement(name); - return (myXmlElem_t)(doc->NewElement(name)); + if (!el) + { + return NULL; + } + + ((tinyxml2::XMLElement *)parent)->InsertEndChild(el); + + return (myXmlElem_t)(el); } void myXml_set_attr(myXmlElem_t elem, const char *name, const char *value)