From daf3bd7f0a6ce63f6dc52c4dba6af1b430f9327c Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 17 Oct 2025 00:03:04 +0100 Subject: [PATCH] gmappedfile: Avoid calling mmap() with a length of zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We were previously relying on it returning `EINVAL` so we could return an error message, but scan-build doesn’t like that, so let’s just explicitly return the same error anyway to shut scan-build up. Signed-off-by: Philip Withnall --- glib/gmappedfile.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/glib/gmappedfile.c b/glib/gmappedfile.c index c8e513b76..222e05703 100644 --- a/glib/gmappedfile.c +++ b/glib/gmappedfile.c @@ -155,6 +155,13 @@ mapped_file_new_from_fd (int fd, file->contents = NULL; return file; } + else if (st.st_size == 0) + { + errno = EINVAL; + file->length = 0; + file->contents = MAP_FAILED; + goto error; + } file->contents = MAP_FAILED; @@ -192,7 +199,7 @@ mapped_file_new_from_fd (int fd, } #endif - +error: if (file->contents == MAP_FAILED) { if (error != NULL)