gmappedfile: Avoid calling mmap() with a length of zero

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 <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall
2025-10-17 00:03:04 +01:00
parent ca1e32f067
commit daf3bd7f0a

View File

@@ -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)