mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-05-03 06:46:38 -04:00
Final code polish for consistency and correctness
- Use int32_t consistently in all loops - Add zero-length check before memcpy - Improve error detection in strtol (comment clarification) - Ensure null terminator always has space reserved Co-authored-by: squassina <8495707+squassina@users.noreply.github.com>
This commit is contained in:
parent
969c68b66d
commit
1350b7787a
2 changed files with 8 additions and 4 deletions
|
|
@ -607,10 +607,13 @@ static char *combine_args_until_empty(char *values[], int count) {
|
|||
}
|
||||
if (remaining > 1) {
|
||||
size_t val_len = strlen(values[i]);
|
||||
// Always leave space for null terminator
|
||||
size_t to_copy = (val_len < remaining - 1) ? val_len : remaining - 1;
|
||||
memcpy(ptr, values[i], to_copy);
|
||||
ptr += to_copy;
|
||||
remaining -= to_copy;
|
||||
if (to_copy > 0) {
|
||||
memcpy(ptr, values[i], to_copy);
|
||||
ptr += to_copy;
|
||||
remaining -= to_copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
*ptr = '\0'; // Null terminate
|
||||
|
|
@ -648,6 +651,7 @@ uint32_t parse_mod(const char *mod_str) {
|
|||
char *endptr;
|
||||
errno = 0;
|
||||
long keycode = strtol(token + 5, &endptr, 10);
|
||||
// Check for conversion errors: overflow or no conversion
|
||||
if (endptr != token + 5 && (*endptr == '\0' || *endptr == ' ') && errno != ERANGE) {
|
||||
switch (keycode) {
|
||||
case 133:
|
||||
|
|
|
|||
|
|
@ -865,7 +865,7 @@ int32_t spawn(const Arg *arg) {
|
|||
// 4. execvp 失败时:清理并退出
|
||||
// If execvp succeeds, this code never runs (process replaced)
|
||||
// If it fails, clean up allocated strings before exiting
|
||||
for (int i = 0; i < alloc_count; i++) {
|
||||
for (int32_t i = 0; i < alloc_count; i++) {
|
||||
free(allocated_strings[i]);
|
||||
}
|
||||
wlr_log(WLR_ERROR, "mango: execvp '%s' failed: %s\n", argv[0],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue