From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Tremer To: development@lists.ipfire.org Subject: Re: [PATCH 2/3] network-functions.pl : Compare correct variables in network_equal Date: Mon, 06 Jan 2020 18:57:19 +0000 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3643278032872380956==" List-Id: --===============3643278032872380956== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Thx. > On 6 Jan 2020, at 17:33, Bernhard Bitsch wrote: >=20 >=20 >=20 >> Gesendet: Montag, 06. Januar 2020 um 18:16 Uhr >> Von: "Michael Tremer" >> An: "Tim FitzGeorge" >> Cc: development(a)lists.ipfire.org >> Betreff: Re: [PATCH 2/3] network-functions.pl : Compare correct variables = in network_equal >>=20 >> Okay. >>=20 >> Did I say that I hate Perl? >>=20 >> I suppose if you tested this, it works. And it must have worked at some po= int before, because there was a test suite. >>=20 >=20 > Not a testsuite, but formal verification with the language definition ( whi= ch is huge in case of Perl ;) ) proves the correctness in this special case. > SCNR >=20 > -Bernhard >=20 >> Acked-by: Michael Tremer >>=20 >> -Michael >>=20 >>> On 28 Dec 2019, at 20:57, Tim FitzGeorge wrote: >>>=20 >>> Hello, >>>=20 >>> On 24/12/2019 13:04, Michael Tremer wrote: >>>> Hello, >>>>=20 >>>> I am still not sure what you are trying to solve here. >>>>=20 >>>> &network2bin() has two possible return values: >>>>=20 >>>> 1) An array with two values >>>>=20 >>>> Or >>>>=20 >>>> 2) Undefined >>>=20 >>> No. It's called in array context so the return value in the latter case >>> is the list ( undef ). >>>=20 >>>>=20 >>>> You are now checking if you have an array with any length but two, but t= his won=E2=80=99t work for undefined. That should at least print a warning th= at you are trying to determine the length of an undefined array. >>>>=20 >>>> So why is this change needed? >>>=20 >>> Partly because the return value is an array and partly because the >>> original code checked the scalar variables $bin1 and $bin2 rather than >>> the arrays @bin1 and @bin2 containing the return values; since these >>> scalars aren't used anywhere, network_equal() always returned undef, >>> which is actually the root cause of my original problem. >>>=20 >>> Tim >>>=20 >>>>=20 >>>> -Michael >>>>=20 >>>>> On 24 Dec 2019, at 13:56, Tim FitzGeorge wro= te: >>>>>=20 >>>>> Check result of network2bin is correct rather than checking non-existent >>>>> variable. >>>>>=20 >>>>> Signed-off-by: Tim FitzGeorge >>>>> --- >>>>> config/cfgroot/network-functions.pl | 2 +- >>>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>>>=20 >>>>> diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/netwo= rk-functions.pl >>>>> index 56b4bceb7..a3f574760 100644 >>>>> --- a/config/cfgroot/network-functions.pl >>>>> +++ b/config/cfgroot/network-functions.pl >>>>> @@ -111,7 +111,7 @@ sub network_equal { >>>>> my @bin1 =3D &network2bin($network1); >>>>> my @bin2 =3D &network2bin($network2); >>>>>=20 >>>>> - if (!defined $bin1 || !defined $bin2) { >>>>> + if (@bin1 !=3D 2 || @bin2 !=3D 2) { >>>>> return undef; >>>>> } >>>>>=20 >>>>> --=20 >>>>> 2.16.4 >>>>>=20 >>>>=20 >>>=20 >>=20 >>=20 --===============3643278032872380956==--