Skip to content

Conversation

@chaowyc
Copy link

@chaowyc chaowyc commented Nov 12, 2025

Description

This patch fixes two issues in append_struct():

  1. Fixed reserve() calculation: Changed from reserve(data_len) to

    reserve(buf.size() + data_len) to correctly account for existing

    buffer size. The original code could fail to allocate sufficient

    space when the buffer already contains data.

  2. Optimized insertion: Replaced loop with N push_back() calls with

    a single insert() operation, reducing function call overhead and

    avoiding potential mid-loop reallocations.

Screenshot

N/A

Issues Fixed or Closed

N/A - This addresses a bug identified through code analysis.

Roadmap Issues

N/A

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

This patch fixes two issues in append_struct():

1. Fixed reserve() calculation: Changed from reserve(data_len) to

   reserve(buf.size() + data_len) to correctly account for existing

   buffer size. The original code could fail to allocate sufficient

   space when the buffer already contains data.

2. Optimized insertion: Replaced loop with N push_back() calls with

   a single insert() operation, reducing function call overhead and

   avoiding potential mid-loop reallocations.
@sonarqubecloud
Copy link

@ReenigneArcher
Copy link
Member

This appears to be a duplicate of your other PR #4415

@chaowyc
Copy link
Author

chaowyc commented Nov 12, 2025

This appears to be a duplicate of your other PR #4415

Yes, that's correct — I previously pushed this PR to my master branch, so it appeared in my earlier PR (#4415), which was merged from master. Feel free to merge the latest one and close this one.

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.

2 participants