[Bf-blender-cvs] [573bda1fae5] master: Fix unused result from mmap() call

Sergey Sharybin noreply at git.blender.org
Thu Jan 28 11:19:15 CET 2021


Commit: 573bda1fae5fbdaf676110ad4ab8be2fed9d766b
Author: Sergey Sharybin
Date:   Wed Jan 27 14:06:47 2021 +0100
Branches: master
https://developer.blender.org/rB573bda1fae5fbdaf676110ad4ab8be2fed9d766b

Fix unused result from mmap() call

The unused result was reported by Clang-Tidy 11.

It does make sense to check for the failed mmap() calls rather than
quietly suppress errors.

In this change failures are reported, but application execution is
not aborted. This is a bit disputable, but it feels to be a safer
thing to do now.

It is unclear how to test the code though, as we don't have any
tools in-place to simulate read errors.

Differential Revision: https://developer.blender.org/D10223

===================================================================

M	source/blender/blenlib/intern/BLI_mmap.c

===================================================================

diff --git a/source/blender/blenlib/intern/BLI_mmap.c b/source/blender/blenlib/intern/BLI_mmap.c
index 210312456d9..2fd162de22c 100644
--- a/source/blender/blenlib/intern/BLI_mmap.c
+++ b/source/blender/blenlib/intern/BLI_mmap.c
@@ -88,7 +88,11 @@ static void sigbus_handler(int sig, siginfo_t *siginfo, void *ptr)
       file->io_error = true;
 
       /* Replace the mapped memory with zeroes. */
-      mmap(file->memory, file->length, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
+      const void *mapped_memory = mmap(
+          file->memory, file->length, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
+      if (mapped_memory == MAP_FAILED) {
+        fprintf(stderr, "SIGBUS handler: Error replacing mapped file with zeros\n");
+      }
 
       return;
     }



More information about the Bf-blender-cvs mailing list