[PATCH v2 02/12] tests/tcg/multiarch/linux-test: Fix error check for shmat

Richard Henderson posted 12 patches 6 years, 3 months ago
Maintainers: Laurent Vivier <laurent@vivier.eu>, Riku Voipio <riku.voipio@iki.fi>, "Alex Bennée" <alex.bennee@linaro.org>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>
There is a newer version of this series
[PATCH v2 02/12] tests/tcg/multiarch/linux-test: Fix error check for shmat
Posted by Richard Henderson 6 years, 3 months ago
The error indicator for this syscall is -1, not 0.

Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tests/tcg/multiarch/linux-test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c
index fa4243fc04..673d7c8a1c 100644
--- a/tests/tcg/multiarch/linux-test.c
+++ b/tests/tcg/multiarch/linux-test.c
@@ -503,8 +503,9 @@ static void test_shm(void)
 
     shmid = chk_error(shmget(IPC_PRIVATE, SHM_SIZE, IPC_CREAT | 0777));
     ptr = shmat(shmid, NULL, 0);
-    if (!ptr)
+    if (ptr == (void *)-1) {
         error("shmat");
+    }
 
     memset(ptr, 0, SHM_SIZE);
 
-- 
2.17.1


Re: [PATCH v2 02/12] tests/tcg/multiarch/linux-test: Fix error check for shmat
Posted by Philippe Mathieu-Daudé 6 years, 3 months ago
On 10/25/19 1:39 PM, Richard Henderson wrote:
> The error indicator for this syscall is -1, not 0.
> 
> Reviewed-by: Laurent Vivier <laurent@vivier.eu>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   tests/tcg/multiarch/linux-test.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c
> index fa4243fc04..673d7c8a1c 100644
> --- a/tests/tcg/multiarch/linux-test.c
> +++ b/tests/tcg/multiarch/linux-test.c
> @@ -503,8 +503,9 @@ static void test_shm(void)
>   
>       shmid = chk_error(shmget(IPC_PRIVATE, SHM_SIZE, IPC_CREAT | 0777));
>       ptr = shmat(shmid, NULL, 0);
> -    if (!ptr)
> +    if (ptr == (void *)-1) {

Oops.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

>           error("shmat");
> +    }
>   
>       memset(ptr, 0, SHM_SIZE);
>   
> 


Re: [PATCH v2 02/12] tests/tcg/multiarch/linux-test: Fix error check for shmat
Posted by Philippe Mathieu-Daudé 6 years, 3 months ago
On 10/25/19 1:39 PM, Richard Henderson wrote:
> The error indicator for this syscall is -1, not 0.
> 

Fixes: e374bfa35bf

A more than 15 years old bug :>

> Reviewed-by: Laurent Vivier <laurent@vivier.eu>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   tests/tcg/multiarch/linux-test.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c
> index fa4243fc04..673d7c8a1c 100644
> --- a/tests/tcg/multiarch/linux-test.c
> +++ b/tests/tcg/multiarch/linux-test.c
> @@ -503,8 +503,9 @@ static void test_shm(void)
>   
>       shmid = chk_error(shmget(IPC_PRIVATE, SHM_SIZE, IPC_CREAT | 0777));
>       ptr = shmat(shmid, NULL, 0);
> -    if (!ptr)
> +    if (ptr == (void *)-1) {
>           error("shmat");
> +    }
>   
>       memset(ptr, 0, SHM_SIZE);
>   
> 


Re: [PATCH v2 02/12] tests/tcg/multiarch/linux-test: Fix error check for shmat
Posted by Laurent Vivier 6 years, 3 months ago
Le 25/10/2019 à 13:39, Richard Henderson a écrit :
> The error indicator for this syscall is -1, not 0.
> 
> Reviewed-by: Laurent Vivier <laurent@vivier.eu>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  tests/tcg/multiarch/linux-test.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c
> index fa4243fc04..673d7c8a1c 100644
> --- a/tests/tcg/multiarch/linux-test.c
> +++ b/tests/tcg/multiarch/linux-test.c
> @@ -503,8 +503,9 @@ static void test_shm(void)
>  
>      shmid = chk_error(shmget(IPC_PRIVATE, SHM_SIZE, IPC_CREAT | 0777));
>      ptr = shmat(shmid, NULL, 0);
> -    if (!ptr)
> +    if (ptr == (void *)-1) {
>          error("shmat");
> +    }
>  
>      memset(ptr, 0, SHM_SIZE);
>  
> 

Applied to my linux-user branch.

Thanks,
Laurent