mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-11 03:24:58 -06:00
tests/qtest: simplify qtest_process_inbuf
Don't both creating a GString to temporarily hold our qtest command. Instead do a simpler g_strndup and use autofree to clean up afterwards. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20250207153112.3939799-5-alex.bennee@linaro.org>
This commit is contained in:
parent
ff6c3b1a16
commit
1e00ebfd80
1 changed files with 8 additions and 12 deletions
|
@ -763,25 +763,21 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Process as much of @inbuf as we can in newline terminated chunks.
|
||||||
|
* Remove the processed commands from @inbuf as we go.
|
||||||
|
*/
|
||||||
static void qtest_process_inbuf(CharBackend *chr, GString *inbuf)
|
static void qtest_process_inbuf(CharBackend *chr, GString *inbuf)
|
||||||
{
|
{
|
||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
while ((end = strchr(inbuf->str, '\n')) != NULL) {
|
while ((end = strchr(inbuf->str, '\n')) != NULL) {
|
||||||
size_t offset;
|
size_t len = end - inbuf->str;
|
||||||
GString *cmd;
|
g_autofree char *cmd = g_strndup(inbuf->str, len);
|
||||||
gchar **words;
|
g_auto(GStrv) words = g_strsplit(cmd, " ", 0);
|
||||||
|
|
||||||
offset = end - inbuf->str;
|
g_string_erase(inbuf, 0, len + 1);
|
||||||
|
|
||||||
cmd = g_string_new_len(inbuf->str, offset);
|
|
||||||
g_string_erase(inbuf, 0, offset + 1);
|
|
||||||
|
|
||||||
words = g_strsplit(cmd->str, " ", 0);
|
|
||||||
qtest_process_command(chr, words);
|
qtest_process_command(chr, words);
|
||||||
g_strfreev(words);
|
|
||||||
|
|
||||||
g_string_free(cmd, TRUE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue