refactor: follow style guide

- reduce variable scope
- prefer initialization over declaration and assignment
This commit is contained in:
dundargoc
2023-11-13 23:40:37 +01:00
committed by dundargoc
parent 1798a4b5e9
commit ac1113ded5
52 changed files with 713 additions and 1269 deletions

View File

@@ -1198,7 +1198,6 @@ char *addstar(char *fname, size_t len, int context)
FUNC_ATTR_NONNULL_RET
{
char *retval;
size_t i, j;
if (context != EXPAND_FILES
&& context != EXPAND_FILES_IN_PATH
@@ -1224,7 +1223,7 @@ char *addstar(char *fname, size_t len, int context)
retval = xstrnsave(fname, len);
} else {
size_t new_len = len + 2; // +2 for '^' at start, NUL at end
for (i = 0; i < len; i++) {
for (size_t i = 0; i < len; i++) {
if (fname[i] == '*' || fname[i] == '~') {
new_len++; // '*' needs to be replaced by ".*"
// '~' needs to be replaced by "\~"
@@ -1243,8 +1242,8 @@ char *addstar(char *fname, size_t len, int context)
retval = xmalloc(new_len);
{
retval[0] = '^';
j = 1;
for (i = 0; i < len; i++, j++) {
size_t j = 1;
for (size_t i = 0; i < len; i++, j++) {
// Skip backslash. But why? At least keep it for custom
// expansion.
if (context != EXPAND_USER_DEFINED