Merge branch 'scan-build-fixes' into 'main'

Fix various scan-build errors

See merge request GNOME/glib!4866
This commit is contained in:
Marco Trevisan
2025-10-17 03:47:16 +02:00
5 changed files with 21 additions and 8 deletions

View File

@@ -3991,7 +3991,12 @@ _resolve_dev_root (void)
} }
} }
/* endmntent() calls fclose() for us, but scan-build doesnt know that */
#if !G_ANALYZER_ANALYZING
endmntent (f); endmntent (f);
#else
fclose (f);
#endif
#ifndef HAVE_GETMNTENT_R #ifndef HAVE_GETMNTENT_R
G_UNLOCK (getmntent); G_UNLOCK (getmntent);

View File

@@ -53,7 +53,7 @@ static gboolean
write_out_typelib (gchar *prefix, write_out_typelib (gchar *prefix,
GITypelib *typelib) GITypelib *typelib)
{ {
FILE *file; FILE *file, *file_owned = NULL;
gsize written; gsize written;
GFile *file_obj; GFile *file_obj;
gchar *filename; gchar *filename;
@@ -86,7 +86,7 @@ write_out_typelib (gchar *prefix,
file_obj = g_file_new_for_path (filename); file_obj = g_file_new_for_path (filename);
tmp_filename = g_strdup_printf ("%s.tmp", filename); tmp_filename = g_strdup_printf ("%s.tmp", filename);
tmp_file_obj = g_file_new_for_path (tmp_filename); tmp_file_obj = g_file_new_for_path (tmp_filename);
file = g_fopen (tmp_filename, "wbe"); file = file_owned = g_fopen (tmp_filename, "wbe");
if (file == NULL) if (file == NULL)
{ {
@@ -106,8 +106,8 @@ write_out_typelib (gchar *prefix,
goto out; goto out;
} }
if (output != NULL) if (file_owned != NULL)
fclose (file); fclose (g_steal_pointer (&file_owned));
if (tmp_filename != NULL) if (tmp_filename != NULL)
{ {
if (!g_file_move (tmp_file_obj, file_obj, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error)) if (!g_file_move (tmp_file_obj, file_obj, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error))

View File

@@ -155,6 +155,13 @@ mapped_file_new_from_fd (int fd,
file->contents = NULL; file->contents = NULL;
return file; return file;
} }
else if (st.st_size == 0)
{
errno = EINVAL;
file->length = 0;
file->contents = MAP_FAILED;
goto error;
}
file->contents = MAP_FAILED; file->contents = MAP_FAILED;
@@ -192,7 +199,7 @@ mapped_file_new_from_fd (int fd,
} }
#endif #endif
error:
if (file->contents == MAP_FAILED) if (file->contents == MAP_FAILED)
{ {
if (error != NULL) if (error != NULL)

View File

@@ -194,7 +194,7 @@ g_rand_new (void)
errno = 0; errno = 0;
r = fread (seed, sizeof (seed), 1, dev_urandom); r = fread (seed, sizeof (seed), 1, dev_urandom);
} }
while G_UNLIKELY (errno == EINTR); while G_UNLIKELY (r != 1 && errno == EINTR);
if (r != 1) if (r != 1)
dev_urandom_exists = FALSE; dev_urandom_exists = FALSE;

View File

@@ -917,9 +917,10 @@ do_exec (gint child_err_report_fd,
*/ */
if (target_fds[i] == child_err_report_fd) if (target_fds[i] == child_err_report_fd)
{ {
child_err_report_fd = dupfd_cloexec (child_err_report_fd, max_target_fd + 1); int new_child_err_report_fd = dupfd_cloexec (child_err_report_fd, max_target_fd + 1);
if (child_err_report_fd < 0) if (new_child_err_report_fd < 0)
write_err_and_exit (child_err_report_fd, CHILD_DUPFD_FAILED); write_err_and_exit (child_err_report_fd, CHILD_DUPFD_FAILED);
child_err_report_fd = new_child_err_report_fd;
} }
if (safe_dup2 (source_fds[i], target_fds[i]) < 0) if (safe_dup2 (source_fds[i], target_fds[i]) < 0)