Avoid compiler casting warnings by assigning to the same type where possible

This saves instructions that are related to casting as well as compiler warnings.
This commit is contained in:
Rose
2023-05-18 14:38:18 -04:00
parent a0b074cc9c
commit e54ba33ea0
50 changed files with 175 additions and 168 deletions

View File

@@ -174,11 +174,11 @@ main(int argc, char *argv[], char *envp[])
/* Initialize the debug subsystem. */
if (sudo_conf_read(NULL, SUDO_CONF_DEBUG) == -1)
exit(EXIT_FAILURE);
return EXIT_FAILURE;
sudo_debug_instance = sudo_debug_register(getprogname(),
NULL, NULL, sudo_conf_debug_files(getprogname()), -1);
if (sudo_debug_instance == SUDO_DEBUG_INSTANCE_ERROR)
exit(EXIT_FAILURE);
return EXIT_FAILURE;
/* Make sure we are setuid root. */
sudo_check_suid(argc > 0 ? argv[0] : "sudo");
@@ -196,7 +196,7 @@ main(int argc, char *argv[], char *envp[])
/* Fill in user_info with user name, uid, cwd, etc. */
if ((user_info = get_user_info(&user_details)) == NULL)
exit(EXIT_FAILURE); /* get_user_info printed error message */
return EXIT_FAILURE; /* get_user_info printed error message */
/* Disable core dumps if not enabled in sudo.conf. */
if (sudo_conf_disable_coredump())
@@ -327,7 +327,7 @@ main(int argc, char *argv[], char *envp[])
}
sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys,
WEXITSTATUS(status));
exit(WEXITSTATUS(status));
return WEXITSTATUS(status);
access_denied:
/* Policy/approval failure, close policy and audit plugins before exit. */
@@ -336,7 +336,7 @@ access_denied:
audit_close(SUDO_PLUGIN_NO_STATUS, 0);
sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys,
EXIT_FAILURE);
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}
int
@@ -500,7 +500,7 @@ static char **
get_user_info(struct user_details *ud)
{
char *cp, **info, path[PATH_MAX];
size_t info_max = 32 + RLIM_NLIMITS;
unsigned int info_max = 32 + RLIM_NLIMITS;
unsigned int i = 0;
mode_t mask;
struct passwd *pw;
@@ -643,8 +643,8 @@ get_user_info(struct user_details *ud)
oom:
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
bad:
while (i--)
free(info[i]);
while (i)
free(info[--i]);
free(info);
debug_return_ptr(NULL);
}
@@ -658,7 +658,7 @@ command_info_to_details(char * const info[], struct command_details *details)
const char *errstr;
char *cp;
id_t id;
int i;
size_t i;
debug_decl(command_info_to_details, SUDO_DEBUG_PCOMM);
memset(details, 0, sizeof(*details));
@@ -692,7 +692,7 @@ command_info_to_details(char * const info[], struct command_details *details)
sudo_debug_printf(SUDO_DEBUG_INFO, "command info from plugin:");
for (i = 0; info[i] != NULL; i++) {
sudo_debug_printf(SUDO_DEBUG_INFO, " %d: %s", i, info[i]);
sudo_debug_printf(SUDO_DEBUG_INFO, " %zu: %s", i, info[i]);
switch (info[i][0]) {
case 'a':
SET_STRING("apparmor_profile=", apparmor_profile);
@@ -900,16 +900,14 @@ command_info_to_details(char * const info[], struct command_details *details)
#ifdef HAVE_SELINUX
if (details->selinux_role != NULL && is_selinux_enabled() > 0) {
SET(details->flags, CD_RBAC_ENABLED);
i = selinux_getexeccon(details->selinux_role, details->selinux_type);
if (i != 0)
if (selinux_getexeccon(details->selinux_role, details->selinux_type) != 0)
exit(EXIT_FAILURE);
}
#endif
#ifdef HAVE_APPARMOR
if (details->apparmor_profile != NULL && apparmor_is_enabled()) {
i = apparmor_prepare(details->apparmor_profile);
if (i != 0)
if (apparmor_prepare(details->apparmor_profile) != 0)
exit(EXIT_FAILURE);
}
#endif
@@ -1077,7 +1075,7 @@ format_plugin_settings(struct plugin_container *plugin)
struct sudo_debug_file *debug_file;
struct sudo_settings *setting;
char **plugin_settings;
unsigned int i = 0;
size_t i = 0;
debug_decl(format_plugin_settings, SUDO_DEBUG_PCOMM);
/* We update the ticket entry by default. */
@@ -1128,8 +1126,8 @@ format_plugin_settings(struct plugin_container *plugin)
debug_return_ptr(plugin_settings);
bad:
while (i--)
free(plugin_settings[i]);
while (i)
free(plugin_settings[--i]);
free(plugin_settings);
debug_return_ptr(NULL);
}
@@ -1268,7 +1266,7 @@ policy_check(int argc, char * const argv[], char *env_add[],
*command_info, *run_argv, *run_envp));
}
static void
sudo_noreturn static void
policy_list(int argc, char * const argv[], int verbose, const char *user)
{
const char *errstr = NULL;
@@ -1313,7 +1311,7 @@ policy_list(int argc, char * const argv[], int verbose, const char *user)
exit(ok != 1);
}
static void
sudo_noreturn static void
policy_validate(char * const argv[])
{
const char *errstr = NULL;
@@ -1357,7 +1355,7 @@ policy_validate(char * const argv[])
exit(ok != 1);
}
static void
sudo_noreturn static void
policy_invalidate(int unlinkit)
{
debug_decl(policy_invalidate, SUDO_DEBUG_PCOMM);