Skip to content

Commit

Permalink
Change: move assignments out of if conditions (base)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmundell committed Feb 25, 2025
1 parent ebeec22 commit 888a97d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
5 changes: 3 additions & 2 deletions base/drop_privileges.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ drop_privileges (gchar *username, GError **error)

if (geteuid () == 0)
{
struct passwd *user_pw = NULL;
struct passwd *user_pw;

if ((user_pw = getpwnam (username)))
user_pw = getpwnam (username);
if (user_pw)
{
if (initgroups (username, user_pw->pw_gid) != 0)
return drop_privileges_error (
Expand Down
21 changes: 14 additions & 7 deletions base/hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,8 @@ gvm_hosts_deduplicate (gvm_hosts_t *hosts)
{
gchar *name;

if ((name = gvm_host_value_str (hosts->hosts[i])))
name = gvm_host_value_str (hosts->hosts[i]);
if (name)
{
gvm_host_t *host, *removed = hosts->hosts[i];

Expand Down Expand Up @@ -1589,7 +1590,8 @@ gvm_hosts_exclude_with_max (gvm_hosts_t *hosts, const char *excluded_str,
{
gchar *name;

if ((name = gvm_host_value_str (excluded_hosts->hosts[i])))
name = gvm_host_value_str (excluded_hosts->hosts[i]);
if (name)
g_hash_table_insert (name_table, name, hosts);
}

Expand All @@ -1598,7 +1600,8 @@ gvm_hosts_exclude_with_max (gvm_hosts_t *hosts, const char *excluded_str,
{
gchar *name;

if ((name = gvm_host_value_str (hosts->hosts[i])))
name = gvm_host_value_str (hosts->hosts[i]);
if (name)
{
if (g_hash_table_lookup (name_table, name))
{
Expand Down Expand Up @@ -1667,7 +1670,8 @@ gvm_hosts_allowed_only (gvm_hosts_t *hosts, const char *deny_hosts_str,
{
gchar *name;

if ((name = gvm_host_value_str (denied_hosts->hosts[i])))
name = gvm_host_value_str (denied_hosts->hosts[i]);
if (name)
g_hash_table_insert (name_deny_table, name, hosts);
}
}
Expand All @@ -1682,7 +1686,8 @@ gvm_hosts_allowed_only (gvm_hosts_t *hosts, const char *deny_hosts_str,
{
gchar *name;

if ((name = gvm_host_value_str (allowed_hosts->hosts[i])))
name = gvm_host_value_str (allowed_hosts->hosts[i]);
if (name)
g_hash_table_insert (name_allow_table, name, hosts);
}
}
Expand All @@ -1693,7 +1698,8 @@ gvm_hosts_allowed_only (gvm_hosts_t *hosts, const char *deny_hosts_str,
{
gchar *name;

if ((name = gvm_host_value_str (hosts->hosts[i])))
name = gvm_host_value_str (hosts->hosts[i]);
if (name)
{
if (denied_hosts != NULL
&& g_hash_table_lookup (name_deny_table, name))
Expand Down Expand Up @@ -2022,7 +2028,8 @@ gvm_hosts_reverse_lookup_unify_excluded (gvm_hosts_t *hosts)
{
gchar *name;

if ((name = gvm_host_reverse_lookup (hosts->hosts[i])))
name = gvm_host_reverse_lookup (hosts->hosts[i]);
if (name)
{
if (g_hash_table_lookup (name_table, name))
{
Expand Down
6 changes: 4 additions & 2 deletions base/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,8 @@ get_routes (void)

interface = g_strndup (items_in_line[0], 64);
/* Cut interface str after ":" if IP aliasing is used. */
if ((char_p = strchr (interface, ':')))
char_p = strchr (interface, ':');
if (char_p)
{
*char_p = '\0';
}
Expand Down Expand Up @@ -1292,7 +1293,8 @@ gvm_get_outgoing_iface (struct sockaddr_storage *target_addr)
return NULL;

// get a connected udp socket
if ((sockfd = get_connected_udp_sock (target_addr)) < 0)
sockfd = get_connected_udp_sock (target_addr);
if (sockfd < 0)
return NULL;
// get socked address which is the addr of the interface we want to get
out_iface_addr.ss_family = family;
Expand Down
3 changes: 2 additions & 1 deletion base/pwpolicy.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ parse_pattern_line (char *line, const char *fname, int lineno, char **descp,
else if (*line == '#' && line[1] == '+') /* Processing instruction. */
{
line += 2;
if ((p = is_keyword (line, "desc")))
p = is_keyword (line, "desc");
if (p)
{
g_free (*descp);
if (*p)
Expand Down

0 comments on commit 888a97d

Please sign in to comment.