[v2,2/4] Network::network2bin: return an empty list in case of error

Message ID 20180212221932.29122-3-berny156@gmx.de
State Dropped
Headers
Series proxy.cgi fixes for bugzilla #10852 |

Commit Message

Bernhard Held Feb. 13, 2018, 9:19 a.m. UTC
  'return undef;' will always return a single value 'undef' even in list context.

sub foo { return undef }
if ( my @x = foo() ) {
    print "oops, we think we got a result";
}
---
 config/cfgroot/network-functions.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Bernhard Bitsch Feb. 13, 2018, 10:52 p.m. UTC | #1
return (); 
(the empty array) makes the code a bit more readable.

> Gesendet: Montag, 12. Februar 2018 um 23:19 Uhr
> Von: "Bernhard Held" <berny156@gmx.de>
> An: development@lists.ipfire.org
> Betreff: [PATCH v2 2/4] Network::network2bin: return an empty list in case of error
>
> 'return undef;' will always return a single value 'undef' even in list context.
> 
> sub foo { return undef }
> if ( my @x = foo() ) {
>     print "oops, we think we got a result";
> }
> ---
>  config/cfgroot/network-functions.pl | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl
> index 93bb646a6..41d36a194 100644
> --- a/config/cfgroot/network-functions.pl
> +++ b/config/cfgroot/network-functions.pl
> @@ -139,7 +139,7 @@ sub network2bin($) {
>  	my $netmask_bin = &ip2bin($netmask);
>  
>  	if (!defined $address_bin || !defined $netmask_bin) {
> -		return undef;
> +		return;
>  	}
>  
>  	my $network_start = $address_bin & $netmask_bin;
> -- 
> 2.16.1
> 
>
  

Patch

diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl
index 93bb646a6..41d36a194 100644
--- a/config/cfgroot/network-functions.pl
+++ b/config/cfgroot/network-functions.pl
@@ -139,7 +139,7 @@  sub network2bin($) {
 	my $netmask_bin = &ip2bin($netmask);
 
 	if (!defined $address_bin || !defined $netmask_bin) {
-		return undef;
+		return;
 	}
 
 	my $network_start = $address_bin & $netmask_bin;