Final refinements for security and performance

- Add explicit null termination for consistency
- Optimize string concatenation to avoid redundant strlen calls
- Track actual characters added to maintain O(n) complexity
- Improve code clarity with better comments

Co-authored-by: squassina <8495707+squassina@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-02-18 09:01:20 +00:00
parent 12fe0abca1
commit 21088fe86a
2 changed files with 15 additions and 5 deletions

View file

@ -77,8 +77,9 @@ void get_layout_abbr(char *abbr, const char *full_name) {
abbr[2] = '\0';
} else {
// 5. 最终回退:返回 "xx"
// strncpy will null-terminate since source is shorter than buffer
// Explicit null termination for consistency
strncpy(abbr, "xx", LAYOUT_ABBR_SIZE - 1);
abbr[LAYOUT_ABBR_SIZE - 1] = '\0';
}
}