Skip to content

Update strlcat.c #18738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Update strlcat.c #18738

wants to merge 1 commit into from

Conversation

itashia
Copy link

@itashia itashia commented Jun 2, 2025

Refactor: Improve variable naming, loop clarity, and safety

  • Renamed variables for better clarity (e.g., nremaining, orig_dst/orig_src for start pointers)
  • Optimized loops by removing unnecessary operations
  • Replaced n != 0 with remaining > 1 for clearer loop conditions
  • Added clearer comments and documentation for function behavior
  • Grouped related code blocks for better structure
  • Removed unnecessary temporary variables
  • Ensured null-termination (\0) to prevent buffer overflows
  • All performance characteristics and original algorithm logic preserved

Refactor: Improve variable naming, loop clarity, and safety

- Renamed variables for better clarity (e.g., `n` → `remaining`, `orig_dst`/`orig_src` for start pointers)
- Optimized loops by removing unnecessary operations
- Replaced `n != 0` with `remaining > 1` for clearer loop conditions
- Added clearer comments and documentation for function behavior
- Grouped related code blocks for better structure
- Removed unnecessary temporary variables
- Ensured null-termination (`\0`) to prevent buffer overflows
- All performance characteristics and original algorithm logic preserved
@itashia itashia requested a review from bukka as a code owner June 2, 2025 11:34
@TimWolla
Copy link
Member

TimWolla commented Jun 2, 2025

see #18740 (comment)

@NattyNarwhal
Copy link
Member

Is there much point in diverging from the upstream code here? If there are issues beyond style with it, then it's worth taking those upstream perhaps. And if it's functional changes, then keep in mind on platforms with strlcpy, then the behaviour diverges from that.

* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* (Original OpenBSD license text preserved above)
Copy link
Member

Choose a reason for hiding this comment

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

The original license text was not preserved.

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