mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-06-29 13:14:48 -04:00
Simplify code based on final review feedback
- Use direct character assignment for constant strings - Remove unnecessary tracking array and cleanup code - Simplify string concatenation logic - Fix length calculation to match actual strncat behavior - Code is cleaner and more maintainable Co-authored-by: squassina <8495707+squassina@users.noreply.github.com>
This commit is contained in:
parent
21088fe86a
commit
5d145cc80f
3 changed files with 11 additions and 23 deletions
|
|
@ -601,21 +601,15 @@ static char *combine_args_until_empty(char *values[], int count) {
|
|||
size_t current_len = 0;
|
||||
for (int i = 0; i < first_empty; i++) {
|
||||
if (i > 0 && current_len < total_len) {
|
||||
size_t remaining = total_len - current_len;
|
||||
size_t to_add = (remaining < 1) ? 0 : 1;
|
||||
if (to_add > 0) {
|
||||
strncat(combined, ",", remaining);
|
||||
current_len += to_add; // We know we added 1 character
|
||||
}
|
||||
strncat(combined, ",", total_len - current_len);
|
||||
current_len++;
|
||||
}
|
||||
if (current_len < total_len) {
|
||||
size_t remaining = total_len - current_len;
|
||||
size_t val_len = strlen(values[i]);
|
||||
size_t to_add = (val_len < remaining) ? val_len : remaining;
|
||||
if (to_add > 0) {
|
||||
strncat(combined, values[i], remaining);
|
||||
current_len += to_add;
|
||||
}
|
||||
size_t will_add = (val_len < remaining) ? val_len : remaining;
|
||||
strncat(combined, values[i], remaining);
|
||||
current_len += will_add;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue