# git-remote: Use of uninitialized value in string ne, line 248

8 messages from 2007-10-24 to 2007-10-25. Participants: martin f krafft, Junio C Hamano, Alex Riesen, Pierre Habouzit, Ralf Wildenhues.
Thread: https://gitlist.dev/t/10450

## martin f krafft, 2007-10-24 11:08

Subject: git-remote: Use of uninitialized value in string ne, line 248
Message-ID: <20071024110807.GA12501@piper.oerlikon.madduck.net>
URL: https://gitlist.dev/e/20071024110807.GA12501%40piper.oerlikon.madduck.net

```
I am useless at Perl, otherwise I'd fix this, but I don't know
what's going on, so best I can do is report it. This is against
current tip of master.

piper:~> git remote show origin
* remote origin
  URL: ssh://git.madduck.net/~/git/etc/mailplate.git
Use of uninitialized value in string ne at /usr/local/stow/git/bin/git-remote line 248.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Tracked remote branches
    master
piper:~> git branch
* master

-- 
martin | http://madduck.net/ | http://two.sentenc.es/
 
"... and so he killed Miguel in a rit of fealous jage."
                                               -- inspector clouseau
 
spamtraps: madduck.bogus@madduck.net

```

## Junio C Hamano, 2007-10-24 11:49

Subject: Re: git-remote: Use of uninitialized value in string ne, line 248
Message-ID: <7vwstc68bk.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vwstc68bk.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <20071024110807.GA12501@piper.oerlikon.madduck.net>

```
martin f krafft <madduck@madduck.net> writes:

> piper:~> git remote show origin
> * remote origin
>   URL: ssh://git.madduck.net/~/git/etc/mailplate.git
> Use of uninitialized value in string ne at /usr/local/stow/git/bin/git-remote line 248.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Perhaps....

 git-remote.perl |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/git-remote.perl b/git-remote.perl
index 9ca3e7e..4cee044 100755
--- a/git-remote.perl
+++ b/git-remote.perl
@@ -244,7 +244,8 @@ sub show_remote {
 	print "* remote $name\n";
 	print "  URL: $info->{'URL'}\n";
 	for my $branchname (sort keys %$branch) {
-		next if ($branch->{$branchname}{'REMOTE'} ne $name);
+		next if (!$branch->{$branchname}{'REMOTE'} ||
+			 $branch->{$branchname}{'REMOTE'} ne $name);
 		my @merged = map {
 			s|^refs/heads/||;
 			$_;

```

## martin f krafft, 2007-10-24 11:59

Subject: Re: git-remote: Use of uninitialized value in string ne, line 248
Message-ID: <20071024115943.GA1016@piper.oerlikon.madduck.net>
URL: https://gitlist.dev/e/20071024115943.GA1016%40piper.oerlikon.madduck.net
In-Reply-To: <7vwstc68bk.fsf@gitster.siamese.dyndns.org>

```
also sprach Junio C Hamano <gitster@pobox.com> [2007.10.24.1349 +0200]:
> -		next if ($branch->{$branchname}{'REMOTE'} ne $name);
> +		next if (!$branch->{$branchname}{'REMOTE'} ||
> +			 $branch->{$branchname}{'REMOTE'} ne $name);

Confirmed: this fixes the issue. Thanks.

-- 
martin | http://madduck.net/ | http://two.sentenc.es/
 
"convictions are more dangerous enemies of truth than lies."
                                                 - friedrich nietzsche
 
spamtraps: madduck.bogus@madduck.net

```

## Alex Riesen, 2007-10-24 19:39

Subject: Re: git-remote: Use of uninitialized value in string ne, line 248
Message-ID: <20071024193954.GA5280@steel.home>
URL: https://gitlist.dev/e/20071024193954.GA5280%40steel.home
In-Reply-To: <7vwstc68bk.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano, Wed, Oct 24, 2007 13:49:51 +0200:
> Perhaps....
> 
>  git-remote.perl |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/git-remote.perl b/git-remote.perl
> index 9ca3e7e..4cee044 100755
> --- a/git-remote.perl
> +++ b/git-remote.perl
> @@ -244,7 +244,8 @@ sub show_remote {
>  	print "* remote $name\n";
>  	print "  URL: $info->{'URL'}\n";
>  	for my $branchname (sort keys %$branch) {
> -		next if ($branch->{$branchname}{'REMOTE'} ne $name);
> +		next if (!$branch->{$branchname}{'REMOTE'} ||

just you never call yor branches "0".

```

## martin f krafft, 2007-10-24 20:27

Subject: Re: git-remote: Use of uninitialized value in string ne, line 248
Message-ID: <20071024202724.GA2292@piper.oerlikon.madduck.net>
URL: https://gitlist.dev/e/20071024202724.GA2292%40piper.oerlikon.madduck.net
In-Reply-To: <20071024193954.GA5280@steel.home>

```
also sprach Alex Riesen <raa.lkml@gmail.com> [2007.10.24.2139 +0200]:
> just you never call yor branches "0".

Wow, Perl is weird. :)

perl -e 'print "The earth is a disk!\n" if ( "earth" == "flat" );'

Is there a way to make it explicit that you're checking for a value
being defined, where a "false" value would count as true, just as
long as there is a value?

-- 
martin | http://madduck.net/ | http://two.sentenc.es/
 
micro$oft dns service terminates abnormally
when it receives a response
to a dns query that was never made.
fix information: run your dns service on a different platform.
                                                            -- bugtraq
 
spamtraps: madduck.bogus@madduck.net

```

## Pierre Habouzit, 2007-10-24 20:39

Subject: Re: git-remote: Use of uninitialized value in string ne, line 248
Message-ID: <20071024203911.GC10900@artemis.corp>
URL: https://gitlist.dev/e/20071024203911.GC10900%40artemis.corp
In-Reply-To: <7vwstc68bk.fsf@gitster.siamese.dyndns.org>

```
On Wed, Oct 24, 2007 at 11:49:51AM +0000, Junio C Hamano wrote:
> martin f krafft <madduck@madduck.net> writes:
> 
> > piper:~> git remote show origin
> > * remote origin
> >   URL: ssh://git.madduck.net/~/git/etc/mailplate.git
> > Use of uninitialized value in string ne at /usr/local/stow/git/bin/git-remote line 248.
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Perhaps....
> 
>  git-remote.perl |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/git-remote.perl b/git-remote.perl
> index 9ca3e7e..4cee044 100755
> --- a/git-remote.perl
> +++ b/git-remote.perl
> @@ -244,7 +244,8 @@ sub show_remote {
>  	print "* remote $name\n";
>  	print "  URL: $info->{'URL'}\n";
>  	for my $branchname (sort keys %$branch) {
> -		next if ($branch->{$branchname}{'REMOTE'} ne $name);
> +		next if (!$branch->{$branchname}{'REMOTE'} ||
> +			 $branch->{$branchname}{'REMOTE'} ne $name);

  This looks better (wrt the "0" issue raised earlier):

+		next unless (defined($branch->{$branchname}{'REMOTE'}) &&
+			 $branch->{$branchname}{'REMOTE'} eq $name);

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

```

## Ralf Wildenhues, 2007-10-24 20:40

Subject: Re: git-remote: Use of uninitialized value in string ne, line 248
Message-ID: <20071024204010.GC15978@ins.uni-bonn.de>
URL: https://gitlist.dev/e/20071024204010.GC15978%40ins.uni-bonn.de
In-Reply-To: <20071024202724.GA2292@piper.oerlikon.madduck.net>

```
* martin f krafft wrote on Wed, Oct 24, 2007 at 10:27:24PM CEST:
> 
> perl -e 'print "The earth is a disk!\n" if ( "earth" == "flat" );'

Well, numerical equality and string equality are two different things,
try eq instead (see: perldoc perlop).

> Is there a way to make it explicit that you're checking for a value
> being defined, where a "false" value would count as true, just as
> long as there is a value?

Yes.  It's called "defined".
  perl -e 'my $a=0; print "yes\n" if defined $a;'

It should be used here, to allow "0" branches.

Cheers,
Ralf

```

## Junio C Hamano, 2007-10-25 01:48

Subject: Re: git-remote: Use of uninitialized value in string ne, line 248
Message-ID: <7vr6jk3qwu.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vr6jk3qwu.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <20071024193954.GA5280@steel.home>

```
Alex Riesen <raa.lkml@gmail.com> writes:

> Junio C Hamano, Wed, Oct 24, 2007 13:49:51 +0200:
>> Perhaps....
>> 
>>  git-remote.perl |    3 ++-
>>  1 files changed, 2 insertions(+), 1 deletions(-)
>> 
>> diff --git a/git-remote.perl b/git-remote.perl
>> index 9ca3e7e..4cee044 100755
>> --- a/git-remote.perl
>> +++ b/git-remote.perl
>> @@ -244,7 +244,8 @@ sub show_remote {
>>  	print "* remote $name\n";
>>  	print "  URL: $info->{'URL'}\n";
>>  	for my $branchname (sort keys %$branch) {
>> -		next if ($branch->{$branchname}{'REMOTE'} ne $name);
>> +		next if (!$branch->{$branchname}{'REMOTE'} ||
>
> just you never call yor branches "0".

Ok, that is about remote name '0' but whatever...

-- >8 --
[PATCH] git-remote: fix "Use of uninitialized value in string ne"

martin f krafft <madduck@madduck.net> writes:

> piper:~> git remote show origin
> * remote origin
>   URL: ssh://git.madduck.net/~/git/etc/mailplate.git
> Use of uninitialized value in string ne at /usr/local/stow/git/bin/git-remote line 248.

This is because there might not be branch.<name>.remote defined but
the code unconditionally dereferences $branch->{$name}{'REMOTE'} and
compares with another string.

Tested-by: Martin F Krafft <madduck@madduck.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 git-remote.perl |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/git-remote.perl b/git-remote.perl
index 8e2dc4d..11630b1 100755
--- a/git-remote.perl
+++ b/git-remote.perl
@@ -244,7 +244,8 @@ sub show_remote {
 	print "* remote $name\n";
 	print "  URL: $info->{'URL'}\n";
 	for my $branchname (sort keys %$branch) {
-		next if ($branch->{$branchname}{'REMOTE'} ne $name);
+		next unless (defined $branch->{$branchname}{'REMOTE'} &&
+			     $branch->{$branchname}{'REMOTE'} eq $name);
 		my @merged = map {
 			s|^refs/heads/||;
 			$_;
-- 
1.5.3.4.1324.ga7925

```
