Avoid malloc in change_tape_menu

* src/buffer.c (change_tape_menu): Avoid unnecessary xstrdup.
This commit is contained in:
Paul Eggert
2024-11-02 10:15:03 -07:00
parent 005f2916b6
commit 5c47fcf187

View File

@@ -1216,9 +1216,8 @@ change_tape_menu (FILE *read_file)
{ {
char *input_buffer = NULL; char *input_buffer = NULL;
size_t size = 0; size_t size = 0;
bool stop = false;
while (!stop) while (true)
{ {
fputc ('\007', stderr); fputc ('\007', stderr);
fprintf (stderr, fprintf (stderr,
@@ -1283,17 +1282,18 @@ change_tape_menu (FILE *read_file)
for (cursor = name; *cursor && *cursor != '\n'; cursor++) for (cursor = name; *cursor && *cursor != '\n'; cursor++)
; ;
*cursor = '\0';
if (name[0]) if (cursor != name)
{ {
/* FIXME: the following allocation is never reclaimed. */ memmove (input_buffer, name, cursor - name);
*archive_name_cursor = xstrdup (name); input_buffer[cursor - name] = '\0';
stop = true; *archive_name_cursor = input_buffer;
/* FIXME: *archive_name_cursor is never freed. */
return;
} }
else
fprintf (stderr, "%s", fprintf (stderr, "%s",
_("File name not specified. Try again.\n")); _("File name not specified. Try again.\n"));
} }
break; break;