mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-31 06:15:37 +00:00
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:
@@ -342,7 +342,7 @@ add_timestamp(struct json_container *jsonc, struct timespec *ts)
|
||||
time_t secs = ts->tv_sec;
|
||||
char timebuf[1024];
|
||||
struct tm gmt;
|
||||
int len;
|
||||
size_t len;
|
||||
debug_decl(add_timestamp, SUDO_DEBUG_PLUGIN);
|
||||
|
||||
if (gmtime_r(&secs, &gmt) == NULL)
|
||||
|
@@ -1514,14 +1514,14 @@ print_usage(FILE *fp)
|
||||
"[-P padding] [-s sections] [input_file]\n", getprogname());
|
||||
}
|
||||
|
||||
static void
|
||||
sudo_noreturn static void
|
||||
usage(void)
|
||||
{
|
||||
print_usage(stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
sudo_noreturn static void
|
||||
help(void)
|
||||
{
|
||||
(void) printf(_("%s - convert between sudoers file formats\n\n"), getprogname());
|
||||
|
@@ -403,7 +403,7 @@ cvtsudoers_make_grlist_item(const struct passwd *pw, char * const *unused1)
|
||||
struct cache_item_grlist *grlitem;
|
||||
struct sudoers_string *s;
|
||||
struct group_list *grlist;
|
||||
int groupname_len;
|
||||
size_t groupname_len;
|
||||
debug_decl(cvtsudoers_make_grlist_item, SUDOERS_DEBUG_NSS);
|
||||
|
||||
/*
|
||||
@@ -421,7 +421,7 @@ cvtsudoers_make_grlist_item(const struct passwd *pw, char * const *unused1)
|
||||
}
|
||||
|
||||
#ifdef _SC_LOGIN_NAME_MAX
|
||||
groupname_len = MAX((int)sysconf(_SC_LOGIN_NAME_MAX), 32);
|
||||
groupname_len = MAX(sysconf(_SC_LOGIN_NAME_MAX), 32);
|
||||
#else
|
||||
groupname_len = MAX(LOGIN_NAME_MAX, 32);
|
||||
#endif
|
||||
|
@@ -185,8 +185,9 @@ resolve_editor(const char *ed, size_t edlen, int nfiles, char * const *files,
|
||||
}
|
||||
if (nfiles != 0) {
|
||||
nargv[nargc++] = (char *)"--";
|
||||
while (nfiles--)
|
||||
do
|
||||
nargv[nargc++] = *files++;
|
||||
while (--nfiles > 0);
|
||||
}
|
||||
nargv[nargc] = NULL;
|
||||
|
||||
@@ -200,8 +201,8 @@ bad:
|
||||
free(editor);
|
||||
free(editor_path);
|
||||
if (nargv != NULL) {
|
||||
while (nargc--) {
|
||||
sudoers_gc_remove(GC_PTR, nargv[nargc]);
|
||||
while (nargc > 0) {
|
||||
sudoers_gc_remove(GC_PTR, nargv[--nargc]);
|
||||
free(nargv[nargc]);
|
||||
}
|
||||
sudoers_gc_remove(GC_PTR, nargv);
|
||||
|
@@ -2345,7 +2345,7 @@ difftm(struct tm *a, struct tm *b)
|
||||
{
|
||||
int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
|
||||
int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
|
||||
int days = (
|
||||
long days = (
|
||||
/* difference in day of year */
|
||||
a->tm_yday - b->tm_yday
|
||||
/* + intervening leap days */
|
||||
@@ -2451,7 +2451,6 @@ main(int argc, char *argv[])
|
||||
(void)printf("\t> ");
|
||||
(void)fflush(stdout);
|
||||
}
|
||||
exit(0);
|
||||
/* NOTREACHED */
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST */
|
||||
|
@@ -811,7 +811,7 @@ difftm(struct tm *a, struct tm *b)
|
||||
{
|
||||
int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
|
||||
int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
|
||||
int days = (
|
||||
long days = (
|
||||
/* difference in day of year */
|
||||
a->tm_yday - b->tm_yday
|
||||
/* + intervening leap days */
|
||||
@@ -917,7 +917,6 @@ main(int argc, char *argv[])
|
||||
(void)printf("\t> ");
|
||||
(void)fflush(stdout);
|
||||
}
|
||||
exit(0);
|
||||
/* NOTREACHED */
|
||||
return 0;
|
||||
}
|
||||
#endif /* TEST */
|
||||
|
@@ -851,7 +851,7 @@ done:
|
||||
static void
|
||||
sudoers_io_close_local(int exit_status, int error, const char **errstr)
|
||||
{
|
||||
int i;
|
||||
unsigned int i;
|
||||
debug_decl(sudoers_io_close_local, SUDOERS_DEBUG_PLUGIN);
|
||||
|
||||
/* Close the files. */
|
||||
|
@@ -637,7 +637,7 @@ display_priv_long(struct sudoers_parse_tree *parse_tree, struct passwd *pw,
|
||||
struct member *m;
|
||||
|
||||
if (new_long_entry(cs, prev_cs)) {
|
||||
int olen;
|
||||
unsigned int olen;
|
||||
|
||||
if (priv->ldap_role != NULL) {
|
||||
sudo_lbuf_append(lbuf, _("\nLDAP Role: %s\n"),
|
||||
@@ -717,7 +717,7 @@ display_priv_long(struct sudoers_parse_tree *parse_tree, struct passwd *pw,
|
||||
if (cs->notbefore != UNSPEC) {
|
||||
char buf[sizeof("CCYYMMDDHHMMSSZ")] = "";
|
||||
struct tm gmt;
|
||||
int len;
|
||||
size_t len;
|
||||
if (gmtime_r(&cs->notbefore, &gmt) != NULL) {
|
||||
len = strftime(buf, sizeof(buf), "%Y%m%d%H%M%SZ", &gmt);
|
||||
if (len != 0 && buf[sizeof(buf) - 1] == '\0')
|
||||
@@ -727,7 +727,7 @@ display_priv_long(struct sudoers_parse_tree *parse_tree, struct passwd *pw,
|
||||
if (cs->notafter != UNSPEC) {
|
||||
char buf[sizeof("CCYYMMDDHHMMSSZ")] = "";
|
||||
struct tm gmt;
|
||||
int len;
|
||||
size_t len;
|
||||
if (gmtime_r(&cs->notafter, &gmt) != NULL) {
|
||||
len = strftime(buf, sizeof(buf), "%Y%m%d%H%M%SZ", &gmt);
|
||||
if (len != 0 && buf[sizeof(buf) - 1] == '\0')
|
||||
|
@@ -656,7 +656,7 @@ sudoers_policy_store_result(bool accepted, char *argv[], char *envp[],
|
||||
mode_t cmnd_umask, char *iolog_path, void *v)
|
||||
{
|
||||
struct sudoers_exec_args *exec_args = v;
|
||||
int info_len = 0;
|
||||
unsigned int info_len = 0;
|
||||
debug_decl(sudoers_policy_store_result, SUDOERS_DEBUG_PLUGIN);
|
||||
|
||||
if (exec_args == NULL)
|
||||
@@ -1051,8 +1051,8 @@ oom:
|
||||
bad:
|
||||
free(audit_msg);
|
||||
audit_msg = NULL;
|
||||
while (info_len--)
|
||||
free(command_info[info_len]);
|
||||
while (info_len)
|
||||
free(command_info[--info_len]);
|
||||
free(command_info);
|
||||
command_info = NULL;
|
||||
debug_return_bool(false);
|
||||
|
@@ -337,7 +337,7 @@ sudo_mkpwent(const char *user, uid_t uid, gid_t gid, const char *home,
|
||||
struct cache_item *item;
|
||||
struct passwd *pw;
|
||||
size_t len, name_len, home_len, shell_len;
|
||||
int i;
|
||||
unsigned int i;
|
||||
debug_decl(sudo_mkpwent, SUDOERS_DEBUG_NSS);
|
||||
|
||||
if (pwcache_byuid == NULL)
|
||||
@@ -648,7 +648,7 @@ sudo_mkgrent(const char *group, gid_t gid, ...)
|
||||
size_t nmem, nsize, total;
|
||||
char *cp, *mem;
|
||||
va_list ap;
|
||||
int i;
|
||||
unsigned int i;
|
||||
debug_decl(sudo_mkgrent, SUDOERS_DEBUG_NSS);
|
||||
|
||||
if (grcache_bygid == NULL)
|
||||
|
@@ -92,7 +92,7 @@ struct dynamic_array {
|
||||
static void
|
||||
free_strvec(char **vec)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; vec[i] != NULL; i++)
|
||||
free(vec[i]);
|
||||
|
@@ -85,7 +85,7 @@ main(int argc, char *argv[])
|
||||
time_t timeoff = 0;
|
||||
pid_t pids[2];
|
||||
char *faketime;
|
||||
int i;
|
||||
unsigned int i;
|
||||
|
||||
initprogname(argc > 0 ? argv[0] : "check_starttime");
|
||||
|
||||
|
@@ -388,8 +388,8 @@ sss_to_sudoers(struct sudo_sss_handle *handle,
|
||||
* The conversion to a sudoers parse tree requires that entries be
|
||||
* in *ascending* order so we we iterate from last to first.
|
||||
*/
|
||||
for (i = sss_result->num_rules; i-- > 0; ) {
|
||||
struct sss_sudo_rule *rule = sss_result->rules + i;
|
||||
for (i = sss_result->num_rules; i; ) {
|
||||
struct sss_sudo_rule *rule = sss_result->rules + --i;
|
||||
struct privilege *priv;
|
||||
int rc;
|
||||
|
||||
|
@@ -1681,14 +1681,14 @@ print_usage(FILE *fp)
|
||||
getprogname());
|
||||
}
|
||||
|
||||
static void
|
||||
sudo_noreturn static void
|
||||
usage(void)
|
||||
{
|
||||
print_usage(stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
sudo_noreturn static void
|
||||
help(void)
|
||||
{
|
||||
(void) printf(_("%s - replay sudo session logs\n\n"), getprogname());
|
||||
|
@@ -36,7 +36,7 @@ get_timestr(time_t tstamp, int log_year)
|
||||
{
|
||||
static char buf[128];
|
||||
struct tm tm;
|
||||
int len;
|
||||
size_t len;
|
||||
|
||||
if (localtime_r(&tstamp, &tm) != NULL) {
|
||||
/* strftime() does not guarantee to NUL-terminate so we must check. */
|
||||
|
@@ -302,7 +302,7 @@ dump_entry(struct timestamp_entry *entry, off_t pos)
|
||||
debug_return;
|
||||
}
|
||||
|
||||
static void
|
||||
sudo_noreturn static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-f timestamp_file] | [-u username]\n",
|
||||
|
@@ -339,7 +339,7 @@ main(int argc, char *argv[])
|
||||
|
||||
done:
|
||||
sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, exitcode);
|
||||
exit(exitcode);
|
||||
return exitcode;
|
||||
}
|
||||
|
||||
static bool
|
||||
@@ -370,7 +370,7 @@ get_editor(int *editor_argc, char ***editor_argv)
|
||||
char *editor_path = NULL, **allowlist = NULL;
|
||||
const char *env_editor = NULL;
|
||||
static const char *files[] = { "+1", "sudoers" };
|
||||
unsigned int allowlist_len = 0;
|
||||
size_t allowlist_len = 0;
|
||||
debug_decl(get_editor, SUDOERS_DEBUG_UTIL);
|
||||
|
||||
/* Build up editor allowlist from def_editor unless env_editor is set. */
|
||||
@@ -412,8 +412,8 @@ get_editor(int *editor_argc, char ***editor_argv)
|
||||
}
|
||||
|
||||
if (allowlist != NULL) {
|
||||
while (allowlist_len--)
|
||||
free(allowlist[allowlist_len]);
|
||||
while (allowlist_len)
|
||||
free(allowlist[--allowlist_len]);
|
||||
free(allowlist);
|
||||
}
|
||||
|
||||
@@ -908,13 +908,11 @@ run_command(const char *path, char *const *argv)
|
||||
switch (pid = sudo_debug_fork()) {
|
||||
case -1:
|
||||
sudo_fatal(U_("unable to execute %s"), path);
|
||||
break; /* NOTREACHED */
|
||||
case 0:
|
||||
closefrom(STDERR_FILENO + 1);
|
||||
execv(path, argv);
|
||||
sudo_warn(U_("unable to run %s"), path);
|
||||
_exit(127);
|
||||
break; /* NOTREACHED */
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
@@ -1319,14 +1317,14 @@ quit(int signo)
|
||||
|
||||
#define VISUDO_USAGE "usage: %s [-chqsV] [[-f] sudoers ]\n"
|
||||
|
||||
static void
|
||||
sudo_noreturn static void
|
||||
usage(void)
|
||||
{
|
||||
(void) fprintf(stderr, VISUDO_USAGE, getprogname());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
sudo_noreturn static void
|
||||
help(void)
|
||||
{
|
||||
(void) printf(_("%s - safely edit the sudoers file\n\n"), getprogname());
|
||||
|
Reference in New Issue
Block a user