Skip to content

Commit 08a5dfa

Browse files
authored
Bug fixes and improvements
- Fixed bugs that could happen when using a custom tag separator and multiple release tags. - Command [A] can no longer be triggered accidentally.
1 parent a1d585b commit 08a5dfa

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

pkgrename.c/pkgrename.c

+21-4
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,13 @@ static struct scan *pkgrename(struct scan *scan)
687687
putchar('\n');
688688
return scan;
689689
}
690-
} while (strchr("ynaetmorcslhqbpT", c) == NULL);
690+
} while (strchr("ynaAetmorcslhqbpT", c) == NULL);
691691
printf("%c\n", c);
692692

693+
static int a_primed;
694+
if (c != 'a' && c != 'A')
695+
a_primed = 0;
696+
693697
// Evaluate user input,
694698
switch (c) {
695699
case 'y': // [Y]es: rename the file.
@@ -698,9 +702,22 @@ static struct scan *pkgrename(struct scan *scan)
698702
case 'n': // [No]: skip file
699703
goto exit;
700704
case 'a': // [A]ll: rename files automatically.
701-
option_yes_to_all = 1;
702-
rename_file(filename, new_basename, path);
703-
goto exit;
705+
a_primed = 1;
706+
set_color(BRIGHT_YELLOW, stdout);
707+
puts("\nPress Shift-[A] now if you really want to automatically rename all remaining files.\n");
708+
set_color(RESET, stdout);
709+
break;
710+
case 'A':
711+
if (a_primed) {
712+
option_yes_to_all = 1;
713+
rename_file(filename, new_basename, path);
714+
goto exit;
715+
} else {
716+
set_color(BRIGHT_YELLOW, stdout);
717+
puts("\nPress [A] to unlock this command.\n");
718+
set_color(RESET, stdout);
719+
}
720+
break;
704721
case 'e': // [E]dit: let user manually enter a new title.
705722
;
706723
char backup[MAX_TITLE_LEN];

pkgrename.c/src/options.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static struct option opts[] = {
7676

7777
void print_version(void)
7878
{
79-
printf("Version 1.09 BETA, build date: %s\n", __DATE__);
79+
printf("Version 1.09, build date: %s\n", __DATE__);
8080
printf("Get the latest version at "
8181
"\"%s\".\n", HOMEPAGE_LINK);
8282
printf("Report bugs, request features, or add missing tags at "

pkgrename.c/src/releaselists.c

+9-14
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,12 @@ int get_release(char **release, const char *string)
162162
} else if (n_found > 1) {
163163
// Return multiple releases as a comma-separated string.
164164
qsort(found, n_found, sizeof(char *), compar_func);
165-
size_t len = strlen(found[0]);
166-
for (int i = 1; i < n_found; i++)
167-
len += strlen(found[i]) + strlen(tag_separator);
168-
char *new_retval = realloc(retval, len + strlen(tag_separator));
169-
if (new_retval == NULL)
170-
exit(EXIT_FAILURE);
171-
retval = new_retval;
172-
retval[0] = '\0';
173-
strcpy(retval, found[0]);
165+
if (retval == NULL)
166+
retval = calloc(MAX_TAG_LEN, 1);
167+
strncpy(retval, found[0], MAX_TAG_LEN);
174168
for (int i = 1; i < n_found; i++) {
175-
strcat(retval, tag_separator);
176-
strcat(retval, found[i]);
169+
strncat(retval, tag_separator, MAX_TAG_LEN - strlen(retval));
170+
strncat(retval, found[i], MAX_TAG_LEN - strlen(retval));
177171
}
178172
*release = retval;
179173
}
@@ -245,14 +239,15 @@ void replace_commas_in_tag(char *tag, const char *string)
245239
size_t taglen = strlen(tag); // Initial length
246240
size_t stringlen = strlen(string);
247241

248-
for (size_t i = 0; i < taglen; i++) {
242+
for (size_t i = 0; i < strlen(tag); i++) {
249243
if (tag[i] == ',') {
250244
// Only do it if there's enough space left in the tag buffer.
251-
if (strlen(tag) + stringlen + 1 >= MAX_TAG_LEN)
245+
if (strlen(tag) + stringlen - 1 >= MAX_TAG_LEN)
252246
return;
253247

254-
memmove(tag + i + stringlen, tag + i + 1, strlen(tag + i + 1));
248+
memmove(tag + i + stringlen, tag + i + 1, strlen(tag + i));
255249
memcpy(tag + i, string, stringlen);
250+
i += stringlen;
256251
}
257252
}
258253
}

0 commit comments

Comments
 (0)