# [FYI PATCH] t/helper/test-lazy-name-hash: fix compilation

7 messages from 2017-12-18 to 2017-12-22. Participants: Stefan Beller, Jonathan Tan, Jeff Hostetler, Junio C Hamano.
Thread: https://gitlist.dev/t/47460

## Stefan Beller, 2017-12-18 21:49

Subject: [FYI PATCH] t/helper/test-lazy-name-hash: fix compilation
Message-ID: <20171218214947.210042-1-sbeller@google.com>
URL: https://gitlist.dev/e/20171218214947.210042-1-sbeller%40google.com

```
I was compiling origin/master today with stricter compiler flags today
and was greeted by

t/helper/test-lazy-init-name-hash.c: In function ‘cmd_main’:
t/helper/test-lazy-init-name-hash.c:172:5: error: ‘nr_threads_used’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     printf("avg [size %8d] [single %f] %c [multi %f %d]\n",
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         nr,
         ~~~
         (double)avg_single/1000000000,
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         (avg_single < avg_multi ? '<' : '>'),
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         (double)avg_multi/1000000000,
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         nr_threads_used);
         ~~~~~~~~~~~~~~~~
t/helper/test-lazy-init-name-hash.c:115:6: note: ‘nr_threads_used’ was declared here
  int nr_threads_used;
      ^~~~~~~~~~~~~~~

I do not see how we can arrive at that line without having `nr_threads_used`
initialized, as we'd have `count > 1`  (which asserts that we ran the
loop above at least once, such that it *should* be initialized).

I do not have time to dive into further analysis.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 t/helper/test-lazy-init-name-hash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 6368a89345..297fb01d61 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -112,7 +112,7 @@ static void analyze_run(void)
 {
 	uint64_t t1s, t1m, t2s, t2m;
 	int cache_nr_limit;
-	int nr_threads_used;
+	int nr_threads_used = 0;
 	int i;
 	int nr;
 
-- 
2.15.1.620.gb9897f4670-goog


```

## Jonathan Tan, 2017-12-18 23:43

Subject: Re: [FYI PATCH] t/helper/test-lazy-name-hash: fix compilation
Message-ID: <20171218154310.aa62ea2c9f094b663393556e@google.com>
URL: https://gitlist.dev/e/20171218154310.aa62ea2c9f094b663393556e%40google.com
In-Reply-To: <20171218214947.210042-1-sbeller@google.com>

```
On Mon, 18 Dec 2017 13:49:47 -0800
Stefan Beller <sbeller@google.com> wrote:

> I was compiling origin/master today with stricter compiler flags today
> and was greeted by
> 
> t/helper/test-lazy-init-name-hash.c: In function ‘cmd_main’:
> t/helper/test-lazy-init-name-hash.c:172:5: error: ‘nr_threads_used’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>      printf("avg [size %8d] [single %f] %c [multi %f %d]\n",
>      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>          nr,
>          ~~~
>          (double)avg_single/1000000000,
>          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>          (avg_single < avg_multi ? '<' : '>'),
>          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>          (double)avg_multi/1000000000,
>          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>          nr_threads_used);
>          ~~~~~~~~~~~~~~~~
> t/helper/test-lazy-init-name-hash.c:115:6: note: ‘nr_threads_used’ was declared here
>   int nr_threads_used;
>       ^~~~~~~~~~~~~~~
> 
> I do not see how we can arrive at that line without having `nr_threads_used`
> initialized, as we'd have `count > 1`  (which asserts that we ran the
> loop above at least once, such that it *should* be initialized).

Your analysis makes sense. (The compiler probably couldn't detect it because
"count" is a static variable, not a local variable.)

> --- a/t/helper/test-lazy-init-name-hash.c
> +++ b/t/helper/test-lazy-init-name-hash.c
> @@ -112,7 +112,7 @@ static void analyze_run(void)
>  {
>  	uint64_t t1s, t1m, t2s, t2m;
>  	int cache_nr_limit;
> -	int nr_threads_used;
> +	int nr_threads_used = 0;
>  	int i;
>  	int nr;

I agree that this is probably the best way to fix it. Another way might
be to omit printing out the number of threads used in the printf that
prints the average statistics.

The best way is probably to not use so many global variables, but that
is out of scope of this change.

```

## Jeff Hostetler, 2017-12-19 14:19

Subject: Re: [FYI PATCH] t/helper/test-lazy-name-hash: fix compilation
Message-ID: <39238da4-c2b8-050d-51e3-675f5515776e@jeffhostetler.com>
URL: https://gitlist.dev/e/39238da4-c2b8-050d-51e3-675f5515776e%40jeffhostetler.com
In-Reply-To: <20171218214947.210042-1-sbeller@google.com>

```


On 12/18/2017 4:49 PM, Stefan Beller wrote:
> I was compiling origin/master today with stricter compiler flags today
> and was greeted by
> 
> t/helper/test-lazy-init-name-hash.c: In function ‘cmd_main’:
> t/helper/test-lazy-init-name-hash.c:172:5: error: ‘nr_threads_used’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>       printf("avg [size %8d] [single %f] %c [multi %f %d]\n",
>       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>           nr,
>           ~~~
>           (double)avg_single/1000000000,
>           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>           (avg_single < avg_multi ? '<' : '>'),
>           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>           (double)avg_multi/1000000000,
>           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>           nr_threads_used);
>           ~~~~~~~~~~~~~~~~
> t/helper/test-lazy-init-name-hash.c:115:6: note: ‘nr_threads_used’ was declared here
>    int nr_threads_used;
>        ^~~~~~~~~~~~~~~
> 
> I do not see how we can arrive at that line without having `nr_threads_used`
> initialized, as we'd have `count > 1`  (which asserts that we ran the
> loop above at least once, such that it *should* be initialized).
> 
> I do not have time to dive into further analysis.
> 
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>   t/helper/test-lazy-init-name-hash.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
> index 6368a89345..297fb01d61 100644
> --- a/t/helper/test-lazy-init-name-hash.c
> +++ b/t/helper/test-lazy-init-name-hash.c
> @@ -112,7 +112,7 @@ static void analyze_run(void)
>   {
>   	uint64_t t1s, t1m, t2s, t2m;
>   	int cache_nr_limit;
> -	int nr_threads_used;
> +	int nr_threads_used = 0;
>   	int i;
>   	int nr;

Agreed. It should not be a problem.  Explicitly initializing it is fine.


Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>



```

## Stefan Beller, 2017-12-20 22:24

Subject: [PATCH] t/helper/test-lazy-name-hash: fix compilation
Message-ID: <20171220222416.130872-1-sbeller@google.com>
URL: https://gitlist.dev/e/20171220222416.130872-1-sbeller%40google.com
In-Reply-To: <39238da4-c2b8-050d-51e3-675f5515776e@jeffhostetler.com>

```
I was compiling origin/master today with the DEVELOPER compiler flags
today and was greeted by

t/helper/test-lazy-init-name-hash.c: In function ‘cmd_main’:
t/helper/test-lazy-init-name-hash.c:172:5: error: ‘nr_threads_used’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     printf("avg [size %8d] [single %f] %c [multi %f %d]\n",
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         nr,
         ~~~
         (double)avg_single/1000000000,
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         (avg_single < avg_multi ? '<' : '>'),
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         (double)avg_multi/1000000000,
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         nr_threads_used);
         ~~~~~~~~~~~~~~~~
t/helper/test-lazy-init-name-hash.c:115:6: note: ‘nr_threads_used’ was declared here
  int nr_threads_used;
      ^~~~~~~~~~~~~~~

Fix this issue by assigning 0 to 'nr_threads_used'.

Acked-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---

Slightly reworded the commit message. I'd really like this patch to be included
such that I can compile git with the DEVELOPER_CFLAGS flags.

 t/helper/test-lazy-init-name-hash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index 6368a89345..297fb01d61 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -112,7 +112,7 @@ static void analyze_run(void)
 {
 	uint64_t t1s, t1m, t2s, t2m;
 	int cache_nr_limit;
-	int nr_threads_used;
+	int nr_threads_used = 0;
 	int i;
 	int nr;
 
-- 
2.15.1.620.gb9897f4670-goog


```

## Junio C Hamano, 2017-12-22 18:15

Subject: Re: [PATCH] t/helper/test-lazy-name-hash: fix compilation
Message-ID: <xmqq7etetyqo.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq7etetyqo.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20171220222416.130872-1-sbeller@google.com>

```
Stefan Beller <sbeller@google.com> writes:

> I was compiling origin/master today with the DEVELOPER compiler flags
> today and was greeted by
>
> t/helper/test-lazy-init-name-hash.c: In function ‘cmd_main’:
> t/helper/test-lazy-init-name-hash.c:172:5: error: ‘nr_threads_used’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>      printf("avg [size %8d] [single %f] %c [multi %f %d]\n",
>      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>          nr,
>          ~~~
>          (double)avg_single/1000000000,
>          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>          (avg_single < avg_multi ? '<' : '>'),
>          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>          (double)avg_multi/1000000000,
>          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>          nr_threads_used);
>          ~~~~~~~~~~~~~~~~
> t/helper/test-lazy-init-name-hash.c:115:6: note: ‘nr_threads_used’ was declared here
>   int nr_threads_used;
>       ^~~~~~~~~~~~~~~
>
> Fix this issue by assigning 0 to 'nr_threads_used'.
>
> Acked-by: Jonathan Tan <jonathantanmy@google.com>
> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>
> Slightly reworded the commit message. I'd really like this patch to be included
> such that I can compile git with the DEVELOPER_CFLAGS flags.

Heh; I do not think there particularly is much difference between
stricter flags and DEVELOPER flags, but I would rather not lose the
removal of duplicated 'today' I did while I queued the previous one
;-)

>
>  t/helper/test-lazy-init-name-hash.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
> index 6368a89345..297fb01d61 100644
> --- a/t/helper/test-lazy-init-name-hash.c
> +++ b/t/helper/test-lazy-init-name-hash.c
> @@ -112,7 +112,7 @@ static void analyze_run(void)
>  {
>  	uint64_t t1s, t1m, t2s, t2m;
>  	int cache_nr_limit;
> -	int nr_threads_used;
> +	int nr_threads_used = 0;
>  	int i;
>  	int nr;

```

## Stefan Beller, 2017-12-22 18:17

Subject: Re: [PATCH] t/helper/test-lazy-name-hash: fix compilation
Message-ID: <CAGZ79kZ9rWYwzrG+fJu2neYVfHSgoR5TrkSmNf_EJeUm46QUvg@mail.gmail.com>
URL: https://gitlist.dev/e/CAGZ79kZ9rWYwzrG%2BfJu2neYVfHSgoR5TrkSmNf_EJeUm46QUvg%40mail.gmail.com
In-Reply-To: <xmqq7etetyqo.fsf@gitster.mtv.corp.google.com>

```
> Heh; I do not think there particularly is much difference between
> stricter flags and DEVELOPER flags, but I would rather not lose the
> removal of duplicated 'today' I did while I queued the previous one
> ;-)


I did not realize it was queued anywhere, please ignore then.

```

## Junio C Hamano, 2017-12-22 20:02

Subject: Re: [PATCH] t/helper/test-lazy-name-hash: fix compilation
Message-ID: <xmqqtvwir0nz.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqtvwir0nz.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <CAGZ79kZ9rWYwzrG+fJu2neYVfHSgoR5TrkSmNf_EJeUm46QUvg@mail.gmail.com>

```
Stefan Beller <sbeller@google.com> writes:

>> Heh; I do not think there particularly is much difference between
>> stricter flags and DEVELOPER flags, but I would rather not lose the
>> removal of duplicated 'today' I did while I queued the previous one
>> ;-)
>
>
> I did not realize it was queued anywhere, please ignore then.

I just did s/stricter/DEVELOPER/ on the one that have been queued.
Thanks.

```
