[PATCH 02/17] Fix load_image error check for mmap

Richard Henderson posted 17 patches 6 months, 2 weeks ago
[PATCH 02/17] Fix load_image error check for mmap
Posted by Richard Henderson 6 months, 2 weeks ago
mmap does not return null on failure, but MAP_FAILED.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 risu.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/risu.c b/risu.c
index 36fc82a..6b6295c 100644
--- a/risu.c
+++ b/risu.c
@@ -362,10 +362,9 @@ static void load_image(const char *imgfile)
     /* Map writable because we include the memory area for store
      * testing in the image.
      */
-    addr =
-        mmap(0, len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd,
-             0);
-    if (!addr) {
+    addr = mmap(0, len, PROT_READ | PROT_WRITE | PROT_EXEC,
+                MAP_PRIVATE, fd, 0);
+    if (addr == MAP_FAILED) {
         perror("mmap");
         exit(EXIT_FAILURE);
     }
-- 
2.34.1
Re: [PATCH 02/17] Fix load_image error check for mmap
Posted by Philippe Mathieu-Daudé 6 months, 1 week ago
On 11/5/24 13:53, Richard Henderson wrote:
> mmap does not return null on failure, but MAP_FAILED.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   risu.c | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)

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