Skip to content

Commit

Permalink
Explicitly discard unused results where necessary
Browse files Browse the repository at this point in the history
setre*id() functions are declared with `warn_unused_result` which makes
them emit a warning when their result is unused. This warning can be
suppressed by using (void) cast in clang, so do this where appropriate.
As gcc doesn't support this, disable the warning completely when gcc is
used.

See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425
  • Loading branch information
mrc0mmand committed Nov 4, 2024
1 parent b0e2d47 commit 473df4b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ compiler_c_flags += cc.get_supported_arguments([
'-Wno-declaration-after-statement',
])

if cc.get_id() == 'gcc'
compiler_c_flags += cc.get_supported_arguments([
# -Wunused-result can't be suppressed by using (void) in gcc, so let's disable it for now
# See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425
'-Wno-unused-result',
])
endif

glib_req_version = '>= 2.30.0'

gio_dep = dependency('gio-2.0', version: glib_req_version)
Expand Down
4 changes: 2 additions & 2 deletions src/polkitbackend/polkitd.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ become_user (const gchar *user,
goto out;
}

setregid (pw->pw_gid, pw->pw_gid);
setreuid (pw->pw_uid, pw->pw_uid);
(void) setregid (pw->pw_gid, pw->pw_gid);
(void) setreuid (pw->pw_uid, pw->pw_uid);
if ((geteuid () != pw->pw_uid) || (getuid () != pw->pw_uid) ||
(getegid () != pw->pw_gid) || (getgid () != pw->pw_gid))
{
Expand Down
6 changes: 3 additions & 3 deletions src/programs/pkexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ main (int argc, char *argv[])
/* if not changing to uid 0, become uid 0 before changing to the user */
if (pw->pw_uid != 0)
{
setreuid (0, 0);
(void) setreuid (0, 0);
if ((geteuid () != 0) || (getuid () != 0))
{
g_printerr ("Error becoming uid 0: %s\n", g_strerror (errno));
Expand Down Expand Up @@ -1021,8 +1021,8 @@ main (int argc, char *argv[])
g_printerr ("Error initializing groups for %s: %s\n", pw->pw_name, g_strerror (errno));
goto out;
}
setregid (pw->pw_gid, pw->pw_gid);
setreuid (pw->pw_uid, pw->pw_uid);
(void) setregid (pw->pw_gid, pw->pw_gid);
(void) setreuid (pw->pw_uid, pw->pw_uid);
if ((geteuid () != pw->pw_uid) || (getuid () != pw->pw_uid) ||
(getegid () != pw->pw_gid) || (getgid () != pw->pw_gid))
{
Expand Down

0 comments on commit 473df4b

Please sign in to comment.