Skip to content

[Repo Assist] improve: add l_buf_push_char and fix l_str_replace size guard#146

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/improve-lbuf-lstr-2026-04-22-62f6f4c-d092b0194e6d09d4
Draft

[Repo Assist] improve: add l_buf_push_char and fix l_str_replace size guard#146
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/improve-lbuf-lstr-2026-04-22-62f6f4c-d092b0194e6d09d4

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist.\n\n## Summary\n\nTwo small improvements to l_os.h:\n\n### 1. l_buf_push_char — new single-character append helper\n\nL_Buf had l_buf_push (raw bytes), l_buf_push_str, l_buf_push_cstr, and l_buf_push_int, but no helper for appending a single character. Building output character-by-character required a local variable and a l_buf_push(&b, &c, 1) call. The new helper is a trivial inline wrapper:\n\nc\nl_buf_push_char(&buf, '"'); // instead of: char q='"'; l_buf_push(&buf, &q, 1);\n\n\n### 2. l_str_replace — explicit size guard\n\nWhen find.len > s.len, the previous loop condition while (pos <= s.len - find.len) produced a size_t wrap-around. While correct (l_str_find returns -1 immediately), the intent was obscured. An explicit early return makes it clear:\n\nc\nif (find.len > s.len) return l_str_dup(a, s);\n\n\n## Test Status\n\n| Platform | Build | Test |\n|:---|:---:|:---:|\n| Linux (gcc) | ✅ | ✅ 1515 assertions |\n| Linux (clang) | ✅ | ✅ 1513 assertions |\n\nARM/AArch64 not available in this runner; changes are platform-independent.

Generated by 🌈 Repo Assist at {run-started}. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1f672aef974f4246124860fc532f82fe8a93a57e

- Add l_buf_push_char(L_Buf *, char) — missing single-character append helper
  (thin wrapper over l_buf_push), with declaration in the core L_Buf API
  section and implementation adjacent to the other l_buf_* functions.

- Add early-return guard in l_str_replace: when find.len > s.len the
  previous while (pos <= s.len - find.len) condition relied on a size_t
  wrap-around to eventually exit. Although C unsigned arithmetic is defined,
  the intent is clearer with an explicit check.

CI: Linux gcc+clang PASS (1515/1513 assertions).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants