[net][lwip-dhcpd] Add missing <string.h> include in dhcp_server_raw.c - #11835
JHB11Hinson wants to merge 1 commit into
Conversation
dhcp_server_raw.c calls memcmp(), memset(), strlen(), strncmp() and strchr() without including <string.h>. They are then implicitly declared as returning int, which is undefined behaviour and, on 64-bit targets, truncates the pointer returned by strchr() when assigned to a char *. Include the missing standard header.
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-09-24 21:26 CST)
📝 Review Instructions
|
拉取/合并请求描述:(PR description)
为什么提交这份PR (why to submit this PR)
components/net/lwip-dhcpd/dhcp_server_raw.c使用了memcmp()、memset()、strlen()、strncmp()和strchr(),但没有包含<string.h>。在 C 中这些函数会被隐式声明为返回int:在 64 位目标上,p = strchr(...)会把 64 位指针截断为 32 位再赋给char *,得到错误地址,属于未定义行为;开启-Werror=implicit-function-declaration时该文件还会直接编译失败。The file calls
memcmp(),memset(),strlen(),strncmp()andstrchr()but does not include<string.h>. They are implicitly declared as returningint; on 64-bit targets thestrchr()result is truncated when assigned to achar *, which is undefined behaviour.你的解决方案是什么 (what is your solution)
在 libc 头文件区块加入
#include <string.h>,与仓库内其它 net 组件(如components/net/netdev/src/netdev.c、components/net/lwip/port/ethernetif.c)保持一致。Add
#include <string.h>to the libc header block, consistent with other net components in the tree.请提供验证的bsp和config (provide the config and bsp)
RT_USING_LWIP+LWIP_USING_DHCPD,对应dhcp_server_raw.c分支)RT_USING_LWIP、LWIP_USING_DHCPD(lwip 2.0.3)bsp/w60x/rtconfig.h+ lwip-2.0.3 头文件,对dhcp_server_raw.c单文件做编译验证(host gcc,-Werror=implicit-function-declaration):修复前 10 处 implicit declaration、退出码 1;修复后 0 处、退出码 0。未做完整板级构建,CI 结果为准。当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up