readline: fix hmp completion issue

The auto completion does not work in some cases.

Case 1.

1. (qemu) info reg
2. Press 'Tab'.
3. It does not auto complete.

Case 2.

1. (qemu) block_resize flo
2. Press 'Tab'.
3. It does not auto complete 'floppy0'.

Since the readline_add_completion_of() may add any completion when
strlen(pfx) is zero, we remove the check with (name[0] == '\0') because
strlen() always returns zero in that case.

Fixes: 52f50b1e9f ("readline: Extract readline_add_completion_of() from monitor")
Cc: Joe Jin <joe.jin@oracle.com>
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
Tested-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
This commit is contained in:
Dongli Zhang 2023-03-02 13:57:50 +01:00 committed by Cédric Le Goater
parent a2b5f8b8ab
commit 9b29a468bd

View File

@ -1189,9 +1189,7 @@ static void cmd_completion(MonitorHMP *mon, const char *name, const char *list)
}
memcpy(cmd, pstart, len);
cmd[len] = '\0';
if (name[0] == '\0') {
readline_add_completion_of(mon->rs, name, cmd);
}
if (*p == '\0') {
break;
}
@ -1335,10 +1333,8 @@ static void monitor_find_completion_by_table(MonitorHMP *mon,
/* block device name completion */
readline_set_completion_index(mon->rs, strlen(str));
while ((blk = blk_next(blk)) != NULL) {
if (str[0] == '\0') {
readline_add_completion_of(mon->rs, str, blk_name(blk));
}
}
break;
case 's':
case 'S':