[gdk-pixbuf] tests: check for mmap failure



commit a82e78f2e815b6cc248b227ef5e00b294c81499e
Author: Tobias Mueller <muelli cryptobitch de>
Date:   Wed Jun 10 21:58:13 2020 +0200

    tests: check for mmap failure
    
    mmap does not return NULL on failure, but rather MAP_FAILED.
    
    https://gitlab.gnome.org/GNOME/gdk-pixbuf/-/issues/158

 tests/pixbuf-readonly-to-mutable.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/tests/pixbuf-readonly-to-mutable.c b/tests/pixbuf-readonly-to-mutable.c
index 7b88458cd..ea8a22f3f 100644
--- a/tests/pixbuf-readonly-to-mutable.c
+++ b/tests/pixbuf-readonly-to-mutable.c
@@ -19,6 +19,7 @@
 
 #include "gdk-pixbuf/gdk-pixbuf.h"
 #include "test-common.h"
+#include <errno.h>
 #include <string.h>
 
 #ifdef G_OS_UNIX
@@ -60,6 +61,7 @@ get_readonly_pixbuf (void)
 #ifdef G_OS_UNIX
   {
     MappedBuf *buf;
+    int saved_errno;
     int pagesize;
     int pages;
     int r;
@@ -76,8 +78,11 @@ get_readonly_pixbuf (void)
     buf->len = pages * pagesize;
     zero_fd = open("/dev/zero", O_RDWR);
     g_assert(zero_fd != -1);
+    saved_errno = errno;
+    errno = 0;
     buf->buf = mmap (NULL, buf->len, PROT_READ | PROT_WRITE, MAP_PRIVATE, zero_fd, 0);
-    g_assert (buf->buf != NULL);
+    g_assert_true (errno >= 0);
+    errno = saved_errno;
     close(zero_fd);
 
     memcpy (buf->buf, gdk_pixbuf_get_pixels (reference), pixlen);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]