Skip to content

ipvsadm: 修复 -Waddress-of-packed-member 与 -Wformat-truncation 告警 - #1064

Open
pubyun wants to merge 1 commit into
iqiyi:develfrom
pubyun:ipvsadm-warnings
Open

ipvsadm: 修复 -Waddress-of-packed-member 与 -Wformat-truncation 告警#1064
pubyun wants to merge 1 commit into
iqiyi:develfrom
pubyun:ipvsadm-warnings

Conversation

@pubyun

@pubyun pubyun commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

背景

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.arraydp_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-member 6 条、-Wformat-truncation 4 条
  • 改后:两者均 0 条,ipvsadm.o 正常编译

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ytwang0320 ytwang0320 self-assigned this Jun 17, 2026
@ytwang0320 ytwang0320 added the pr/codes-reviewed-ok code review passed and no problem found label Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr/codes-reviewed-ok code review passed and no problem found

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants