Cast int to size_t before adding instead of casting the result.

Quiets PVS-Studio warning V1028.
This commit is contained in:
Todd C. Miller
2023-08-21 12:50:31 -06:00
parent 9f05bfd298
commit c6987aa26e
6 changed files with 9 additions and 8 deletions

View File

@@ -286,7 +286,8 @@ find_editor(int nfiles, char * const files[], char **argv_out[])
}
if (editor_path != editor)
free(editor);
nargv = reallocarray(NULL, (size_t)(nargc + 1 + nfiles + 1), sizeof(char *));
nargv = reallocarray(NULL, (size_t)nargc + 1 + (size_t)nfiles + 1,
sizeof(char *));
if (nargv == NULL) {
sudo_log(SUDO_CONV_ERROR_MSG, "unable to allocate memory\n");
free(editor_path);

View File

@@ -158,7 +158,7 @@ resolve_editor(const char *ed, size_t edlen, int nfiles, char * const *files,
nargc++;
if (nfiles != 0)
nargc += nfiles + 1;
nargv = reallocarray(NULL, (size_t)(nargc + 1), sizeof(char *));
nargv = reallocarray(NULL, (size_t)nargc + 1, sizeof(char *));
if (nargv == NULL)
goto oom;
sudoers_gc_add(GC_PTR, nargv);

View File

@@ -206,7 +206,7 @@ group_plugin_load(const struct sudoers_context *ctx, const char *plugin_info)
}
}
if (ac != 0) {
argv = reallocarray(NULL, (size_t)(ac + 1), sizeof(char *));
argv = reallocarray(NULL, (size_t)ac + 1, sizeof(char *));
if (argv == NULL) {
sudo_warnx(U_("%s: %s"), __func__,
U_("unable to allocate memory"));

View File

@@ -796,7 +796,7 @@ sudoers_policy_store_result(struct sudoers_context *ctx, bool accepted,
/* We reserve an extra spot in the list for the effective gid. */
glsize = sizeof("runas_groups=") - 1 +
((size_t)(gidlist->ngids + 1) * (MAX_UID_T_LEN + 1));
(((size_t)gidlist->ngids + 1) * (MAX_UID_T_LEN + 1));
gid_list = malloc(glsize);
if (gid_list == NULL) {
sudo_gidlist_delref(gidlist);

View File

@@ -1551,11 +1551,11 @@ find_sessions(const char *dir, regex_t *re, const char *user, const char *tty)
/* Check for dir with a log file. */
if (lstat(pathbuf, &sb) == 0 && S_ISREG(sb.st_mode)) {
pathbuf[sdlen + (size_t)(len - 4)] = '\0';
pathbuf[sdlen + (size_t)len - 4] = '\0';
list_session(&lbuf, pathbuf, re, user, tty);
} else {
/* Strip off "/log" and recurse if a non-log dir. */
pathbuf[sdlen + (size_t)(len - 4)] = '\0';
pathbuf[sdlen + (size_t)len - 4] = '\0';
if (checked_type ||
(lstat(pathbuf, &sb) == 0 && S_ISDIR(sb.st_mode)))
find_sessions(pathbuf, re, user, tty);

View File

@@ -1884,7 +1884,7 @@ ptrace_intercept_execve(pid_t pid, struct intercept_closure *closure)
*/
if (argv_mismatch) {
/* argv pointers */
space += (size_t)(argc + 1 + regs.compat) * regs.wordsize;
space += ((size_t)argc + 1 + regs.compat) * regs.wordsize;
/* argv strings */
for (argc = 0; closure->run_argv[argc] != NULL; argc++) {
@@ -1905,7 +1905,7 @@ ptrace_intercept_execve(pid_t pid, struct intercept_closure *closure)
set_sc_arg2(&regs, sp);
/* Skip over argv pointers (plus NULL) for string table. */
strtab += (size_t)(argc + 1 + regs.compat) * regs.wordsize;
strtab += ((size_t)argc + 1 + regs.compat) * regs.wordsize;
nwritten = ptrace_write_vec(pid, &regs, closure->run_argv,
sp, strtab);