masqmail

diff src/address.c @ 23:4a3bc3a7afbe

refactoring: early exit instead of deep if levels
author meillo@marmaro.de
date Fri, 05 Dec 2008 11:32:26 +0100
parents a8f3424347dc
children bc9d9cd9ee8e
line diff
     1.1 --- a/src/address.c	Fri Dec 05 11:26:24 2008 +0100
     1.2 +++ b/src/address.c	Fri Dec 05 11:32:26 2008 +0100
     1.3 @@ -35,11 +35,10 @@
     1.4  create_address_qualified(gchar * path, gboolean is_rfc821, gchar * domain)
     1.5  {
     1.6  	address *addr = create_address(path, is_rfc821);
     1.7 -	if (addr != NULL) {
     1.8 -		if (addr->domain == NULL)
     1.9 +
    1.10 +	if (addr != NULL && addr->domain == NULL) {
    1.11  			addr->domain = g_strdup(domain);
    1.12  	}
    1.13 -
    1.14  	return addr;
    1.15  }
    1.16  
    1.17 @@ -76,26 +75,29 @@
    1.18  {
    1.19  	address *addr = NULL;
    1.20  
    1.21 -	if (orig) {
    1.22 -		addr = g_malloc(sizeof(address));
    1.23 -		if (addr) {
    1.24 -			addr->address = g_strdup(orig->address);
    1.25 +	if (!orig) {
    1.26 +		return NULL;
    1.27 +	}
    1.28  
    1.29 -			if (l_part == NULL)
    1.30 -				addr->local_part = g_strdup(orig->local_part);
    1.31 -			else
    1.32 -				addr->local_part = g_strdup(l_part);
    1.33 +	if ((addr = g_malloc(sizeof(address))) == NULL) {
    1.34 +		return NULL;
    1.35 +	}
    1.36  
    1.37 -			if (dom == NULL)
    1.38 -				addr->domain = g_strdup(orig->domain);
    1.39 -			else
    1.40 -				addr->domain = g_strdup(dom);
    1.41 +	addr->address = g_strdup(orig->address);
    1.42  
    1.43 -			addr->flags = 0;
    1.44 -			addr->children = NULL;
    1.45 -			addr->parent = NULL;
    1.46 -		}
    1.47 -	}
    1.48 +	if (l_part == NULL)
    1.49 +		addr->local_part = g_strdup(orig->local_part);
    1.50 +	else
    1.51 +		addr->local_part = g_strdup(l_part);
    1.52 +
    1.53 +	if (dom == NULL)
    1.54 +		addr->domain = g_strdup(orig->domain);
    1.55 +	else
    1.56 +		addr->domain = g_strdup(dom);
    1.57 +
    1.58 +	addr->flags = 0;
    1.59 +	addr->children = NULL;
    1.60 +	addr->parent = NULL;
    1.61  	return addr;
    1.62  }
    1.63