ext/snmp: minor cleanup in suffix-as-keys walk path
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Three pre-existing issues in the SNMP_USE_SUFFIX_AS_KEYS | SNMP_CMD_WALK code path in php_snmp() (ext/snmp/snmp.c), noticed while reviewing #21341.
1. Redundant snprint_objid call
snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length); // writes full OID
if (rootlen <= vars->name_length && snmp_oid_compare(root, rootlen, vars->name, rootlen) == 0) {
// snprintf loop overwrites buf2 entirely with the suffix
When the if condition is true (the normal walk case), buf2 is written twice and the snprint_objid result is discarded. The call only has effect as a fallback when the condition fails — but in that case SUFFIX_AS_KEYS mode silently returns a full OID as the key, mixing formats in the result array.
Suggestion: move the snprint_objid call into the else branch so it only runs when needed.
2. Empty-suffix key collision
When rootlen == vars->name_length (exact match on the walk root OID), the while loop never executes, pos stays 0, and buf2[0] = '\0'. The entry is added with key "". Multiple such OIDs would clobber each other in the returned array.
Worth deciding whether this case should be excluded, use the full OID as fallback, or is simply impossible in practice (in which case an assertion would document the invariant).
3. int count signed/unsigned comparison
count is declared int at line 111 but compared against vars->name_length (size_t) throughout the function, producing -Wsign-compare warnings. Changing to size_t is mechanical but touches multiple loop sites across the function.
Happy to send a PR covering all three if the approach looks reasonable.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 ext/snmp/snmp.c 中的 php_snmp() 开始,跟踪 SNMP_USE_SUFFIX_AS_KEYS | SNMP_CMD_WALK 路径。检查后缀构造、精确根情况,以及所有涉及 count 和 vars->name_length 的比较。完成的标准是移除冗余格式化,决定并覆盖空键行为,并处理 signed/unsigned 警告。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c
- 领域
- networking
- Issue 类型
- 重构
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100