Skip to content

Fix minor inconsistency in connFormatAddr size argument#3098

Merged
enjoy-binbin merged 1 commit into
valkey-io:unstablefrom
vitahlin:vitah-refactor
Jan 23, 2026
Merged

Fix minor inconsistency in connFormatAddr size argument#3098
enjoy-binbin merged 1 commit into
valkey-io:unstablefrom
vitahlin:vitah-refactor

Conversation

@vitahlin

@vitahlin vitahlin commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

Type: Refactoring / Code Cleanup

Description: While reviewing the connection layer logic, I noticed a minor inconsistency in how buffer sizes are passed to connFormatAddr.

In the error handling block of acceptCommonHandler, sizeof(addr) is currently used for both the remote address and the local address buffers. While both addr and laddr are defined with the same size (NET_ADDR_STR_LEN), it is more idiomatic and safer to use the sizeof of the actual buffer being populated.

This change ensures:

  • Defensive Programming: Prevents potential buffer overflows or truncation issues if the array sizes are changed independently in the future.
  • Code Clarity: Removes ambiguity for future maintainers and ensures the logic is self-consistent.

Code Comparison:

// Before
char addr[NET_ADDR_STR_LEN] = {0};
char laddr[NET_ADDR_STR_LEN] = {0};
connFormatAddr(conn, addr, sizeof(addr), 1);
connFormatAddr(conn, laddr, sizeof(addr), 0); // Using size of the wrong buffer

// After
char addr[NET_ADDR_STR_LEN] = {0};
char laddr[NET_ADDR_STR_LEN] = {0};
connFormatAddr(conn, addr, sizeof(addr), 1);
connFormatAddr(conn, laddr, sizeof(laddr), 0); // Correctly uses sizeof(laddr)

Signed-off-by: Vitah Lin <vitahlin@gmail.com>
@codecov

codecov Bot commented Jan 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.35%. Comparing base (231a9e7) to head (e54a79e).
⚠️ Report is 1 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #3098      +/-   ##
============================================
- Coverage     74.41%   74.35%   -0.06%     
============================================
  Files           129      129              
  Lines         71013    71013              
============================================
- Hits          52843    52804      -39     
- Misses        18170    18209      +39     
Files with missing lines Coverage Δ
src/networking.c 89.75% <100.00%> (-0.07%) ⬇️

... and 22 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@enjoy-binbin enjoy-binbin merged commit be0a572 into valkey-io:unstable Jan 23, 2026
25 checks passed
@vitahlin vitahlin deleted the vitah-refactor branch January 23, 2026 07:21
harrylin98 pushed a commit to harrylin98/valkey_forked that referenced this pull request Feb 19, 2026
Minor fix to use the right var.

Signed-off-by: Vitah Lin <vitahlin@gmail.com>
hpatro pushed a commit to hpatro/valkey that referenced this pull request Mar 5, 2026
Minor fix to use the right var.

Signed-off-by: Vitah Lin <vitahlin@gmail.com>
Signed-off-by: Harkrishn Patro <bunty.hari@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants