ipvsadm: 修复 -Waddress-of-packed-member 与 -Wformat-truncation 告警 - #1064
Open
pubyun wants to merge 1 commit into
Open
ipvsadm: 修复 -Waddress-of-packed-member 与 -Wformat-truncation 告警#1064pubyun wants to merge 1 commit into
pubyun wants to merge 1 commit into
Conversation
ipvsadm.c emitted two classes of pre-existing GCC warnings:
- -Waddress-of-packed-member: print_conn_entry()/inet_addr_equal()/
print_service_and_{blklsts,whtlsts}() were called with the address of an
element of a packed conf array (ip_vs_conn_array.array,
dp_vs_{blklst,whtlst}_conf_array.{blklsts,whtlsts}), which may be
unaligned. Copy the element into an aligned local first, then take its
address.
- -Wformat-truncation: the vip_port[64] buffer can be too small for the
worst-case "[%s]:%s" of vip[64] + vport[8]. Enlarge it to 80.
No functional change.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
该 PR 旨在清理 tools/ipvsadm/ipvsadm.c 在 GCC 构建时出现的两类既有告警(-Waddress-of-packed-member 与 -Wformat-truncation),按 PR 描述不引入功能改动,主要通过“拷贝出 packed 数组元素到局部对齐对象再取地址”和“增大字符串缓冲区”来消除告警。
Changes:
- 对 packed 的连接/黑白名单配置数组元素先拷贝到局部变量,再将局部变量地址传入后续函数,避免
-Waddress-of-packed-member。 - 将
vip_port缓冲区从 64 扩大到 80,避免snprintf组合 IPv6 字符串时触发-Wformat-truncation。
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
ipvsadm.c在构建时产生两类 pre-existing 的 GCC 告警,本 PR 予以清理(无功能改动)。改动
-Waddress-of-packed-member(6 处)print_conn_entry()/inet_addr_equal()/print_service_and_{blklsts,whtlsts}()被传入了 packed 配置数组(ip_vs_conn_array.array、dp_vs_{blklst,whtlst}_conf_array.{blklsts,whtlsts})元素的地址,该地址可能未对齐。改为先把元素拷贝到对齐的局部变量,再取其地址。-Wformat-truncation(4 处)vip_port[64]在极端情况下不足以容纳"[%s]:%s"(vip[64]+vport[8])。将其扩大到 80。验证
同一编译旗标下 before/after 对比:
-Waddress-of-packed-member6 条、-Wformat-truncation4 条ipvsadm.o正常编译