diff mbox series

[3/6] tests/qtest/hd-geo-test: Fix checks on mkstemp() return value

Message ID 20210525134458.6675-4-peter.maydell@linaro.org (mailing list archive)
State New, archived
Headers show
Series tests: Fix some minor Coverity issues | expand

Commit Message

Peter Maydell May 25, 2021, 1:44 p.m. UTC
Coverity notices that the checks against mkstemp() failing in
create_qcow2_with_mbr() are wrong: mkstemp returns -1 on failure but
the check is just "g_assert(fd)".  Fix to use "g_assert(fd >= 0)",
matching the correct check in create_test_img().

Fixes: Coverity CID 1432274
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 tests/qtest/hd-geo-test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Philippe Mathieu-Daudé May 25, 2021, 1:59 p.m. UTC | #1
On 5/25/21 3:44 PM, Peter Maydell wrote:
> Coverity notices that the checks against mkstemp() failing in
> create_qcow2_with_mbr() are wrong: mkstemp returns -1 on failure but
> the check is just "g_assert(fd)".  Fix to use "g_assert(fd >= 0)",
> matching the correct check in create_test_img().
> 
> Fixes: Coverity CID 1432274
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  tests/qtest/hd-geo-test.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Stefan Berger May 25, 2021, 4:14 p.m. UTC | #2
On 5/25/21 9:44 AM, Peter Maydell wrote:
> Coverity notices that the checks against mkstemp() failing in
> create_qcow2_with_mbr() are wrong: mkstemp returns -1 on failure but
> the check is just "g_assert(fd)".  Fix to use "g_assert(fd >= 0)",
> matching the correct check in create_test_img().
>
> Fixes: Coverity CID 1432274
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>


> ---
>   tests/qtest/hd-geo-test.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
> index f7b7cfbc2d1..113126ae06c 100644
> --- a/tests/qtest/hd-geo-test.c
> +++ b/tests/qtest/hd-geo-test.c
> @@ -464,7 +464,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
>       }
>
>       fd = mkstemp(raw_path);
> -    g_assert(fd);
> +    g_assert(fd >= 0);
>       close(fd);
>
>       fd = open(raw_path, O_WRONLY);
> @@ -474,7 +474,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
>       close(fd);
>
>       fd = mkstemp(qcow2_path);
> -    g_assert(fd);
> +    g_assert(fd >= 0);
>       close(fd);
>
>       qemu_img_path = getenv("QTEST_QEMU_IMG");
diff mbox series

Patch

diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index f7b7cfbc2d1..113126ae06c 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -464,7 +464,7 @@  static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
     }
 
     fd = mkstemp(raw_path);
-    g_assert(fd);
+    g_assert(fd >= 0);
     close(fd);
 
     fd = open(raw_path, O_WRONLY);
@@ -474,7 +474,7 @@  static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
     close(fd);
 
     fd = mkstemp(qcow2_path);
-    g_assert(fd);
+    g_assert(fd >= 0);
     close(fd);
 
     qemu_img_path = getenv("QTEST_QEMU_IMG");