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

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

Commit Message

Bernhard Held Feb. 15, 2018, 6:35 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

Michael Tremer Feb. 15, 2018, 9:12 a.m. UTC | #1
Hello,

did you check if any other functions need to be changed in order to
reflect this change?

Many functions use the output of this one.

-Michael

On Wed, 2018-02-14 at 20:35 +0100, Bernhard Held wrote:
> '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 070e14d0f..7cd56f799 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;
  
Bernhard Bitsch Feb. 15, 2018, 9:59 a.m. UTC | #2
Hello,

if I can help, I could look at this also.
Some "cosmetics" (indentions, placing { on the line of 'if', ... ) could make the code more readable. These produce some greater patches without a gain in correctness but in maintainability.

Regards,
Bernhard Bitsch

> Gesendet: Mittwoch, 14. Februar 2018 um 23:12 Uhr
> Von: "Michael Tremer" <michael.tremer@ipfire.org>
> An: "Bernhard Held" <berny156@gmx.de>, development@lists.ipfire.org
> Betreff: Re: [PATCH v3 2/4] Network::network2bin: return an empty list in case of error
>
> Hello,
> 
> did you check if any other functions need to be changed in order to
> reflect this change?
> 
> Many functions use the output of this one.
> 
> -Michael
> 
> On Wed, 2018-02-14 at 20:35 +0100, Bernhard Held wrote:
> > '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 070e14d0f..7cd56f799 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;
>
  

Patch

diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl
index 070e14d0f..7cd56f799 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;