[PATCH v5 7/9] tests/x86: replace snprint() by g_strdup_printf() in drive_del-test

Michael Labiuk via posted 9 patches 3 years, 4 months ago
Maintainers: Thomas Huth <thuth@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
[PATCH v5 7/9] tests/x86: replace snprint() by g_strdup_printf() in drive_del-test
Posted by Michael Labiuk via 3 years, 4 months ago
Using g_autofree char* and  g_strdup_printf(...) instead of ugly
snprintf on stack array.

Signed-off-by: Michael Labiuk <michael.labiuk@virtuozzo.com>
---
 tests/qtest/drive_del-test.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/tests/qtest/drive_del-test.c b/tests/qtest/drive_del-test.c
index 44b9578801..106c613f4f 100644
--- a/tests/qtest/drive_del-test.c
+++ b/tests/qtest/drive_del-test.c
@@ -123,12 +123,10 @@ static const char *qvirtio_get_dev_type(void)
 
 static void device_add(QTestState *qts)
 {
-    QDict *response;
-    char driver[32];
-    snprintf(driver, sizeof(driver), "virtio-blk-%s",
-             qvirtio_get_dev_type());
-
-    response = qtest_qmp(qts, "{'execute': 'device_add',"
+    g_autofree char *driver = g_strdup_printf("virtio-blk-%s",
+                                              qvirtio_get_dev_type());
+    QDict *response =
+               qtest_qmp(qts, "{'execute': 'device_add',"
                               " 'arguments': {"
                               "   'driver': %s,"
                               "   'drive': 'drive0',"
-- 
2.34.1
Re: [PATCH v5 7/9] tests/x86: replace snprint() by g_strdup_printf() in drive_del-test
Posted by Philippe Mathieu-Daudé 3 years, 3 months ago
On 30/9/22 00:35, Michael Labiuk via wrote:
> Using g_autofree char* and  g_strdup_printf(...) instead of ugly
> snprintf on stack array.
> 
> Signed-off-by: Michael Labiuk <michael.labiuk@virtuozzo.com>
> ---
>   tests/qtest/drive_del-test.c | 10 ++++------
>   1 file changed, 4 insertions(+), 6 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>


Re: [PATCH v5 7/9] tests/x86: replace snprint() by g_strdup_printf() in drive_del-test
Posted by Thomas Huth 3 years, 4 months ago
On 30/09/2022 00.35, Michael Labiuk via wrote:
> Using g_autofree char* and  g_strdup_printf(...) instead of ugly
> snprintf on stack array.
> 
> Signed-off-by: Michael Labiuk <michael.labiuk@virtuozzo.com>
> ---
>   tests/qtest/drive_del-test.c | 10 ++++------
>   1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/tests/qtest/drive_del-test.c b/tests/qtest/drive_del-test.c
> index 44b9578801..106c613f4f 100644
> --- a/tests/qtest/drive_del-test.c
> +++ b/tests/qtest/drive_del-test.c
> @@ -123,12 +123,10 @@ static const char *qvirtio_get_dev_type(void)
>   
>   static void device_add(QTestState *qts)
>   {
> -    QDict *response;
> -    char driver[32];
> -    snprintf(driver, sizeof(driver), "virtio-blk-%s",
> -             qvirtio_get_dev_type());
> -
> -    response = qtest_qmp(qts, "{'execute': 'device_add',"
> +    g_autofree char *driver = g_strdup_printf("virtio-blk-%s",
> +                                              qvirtio_get_dev_type());
> +    QDict *response =
> +               qtest_qmp(qts, "{'execute': 'device_add',"
>                                 " 'arguments': {"
>                                 "   'driver': %s,"
>                                 "   'drive': 'drive0',"

Reviewed-by: Thomas Huth <thuth@redhat.com>