# [PATCH] get_local_heads(): do not return random pointer if there is no head

2 messages from 2009-04-16 to 2009-04-18. Participants: Nguyễn Thái Ngọc Duy, Junio C Hamano.
Thread: https://gitlist.dev/t/18906

## Nguyễn Thái Ngọc Duy, 2009-04-16 22:16

Subject: [PATCH] get_local_heads(): do not return random pointer if there is no head
Message-ID: <1239920183-29512-1-git-send-email-pclouds@gmail.com>
URL: https://gitlist.dev/e/1239920183-29512-1-git-send-email-pclouds%40gmail.com

```
it's silly to do this:

mkdir foo && cd foo && git init && git push somewhere.git

but segfault should not happen even in that case.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 remote.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/remote.c b/remote.c
index d12140e..63f749c 100644
--- a/remote.c
+++ b/remote.c
@@ -1493,7 +1493,7 @@ static int one_local_ref(const char *refname, const unsigned char *sha1, int fla
 
 struct ref *get_local_heads(void)
 {
-	struct ref *local_refs, **local_tail = &local_refs;
+	struct ref *local_refs = NULL, **local_tail = &local_refs;
 	for_each_ref(one_local_ref, &local_tail);
 	return local_refs;
 }
-- 
1.6.2.2.693.g5a1be

```

## Junio C Hamano, 2009-04-18 05:02

Subject: Re: [PATCH] get_local_heads(): do not return random pointer if there is no head
Message-ID: <7vljpyy2pj.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vljpyy2pj.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1239920183-29512-1-git-send-email-pclouds@gmail.com>

```
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> it's silly to do this:
>
> mkdir foo && cd foo && git init && git push somewhere.git
>
> but segfault should not happen even in that case.

Thanks.

```
