t/helper/test-lazy-name-hash: fix compilation
PATCH 1/1 t/helper/test-lazy-name-hash: fix compilation
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.
--- t/helper/test-lazy-init-name-hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/helper/test-lazy-init-name-hash.c +1 -1
@@ -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;
Signature · 1 line
2.15.1.620.gb9897f4670-goog
Quoted 21 lines · On Mon, 18 Dec 2017 13:49:47 -0800 Stefan Beller <[email protected]> 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; ^~~~~~~~~~~~~~~
Quoted 3 lines
I do not see how we can arrive at that line without having
nr_threads_usedinitialized, as we'd havecount > 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.)
t/helper/test-lazy-init-name-hash.c static void analyze_run(void) · line 117
Quoted 10 lines
t/helper/test-lazy-init-name-hash.c +1
-1@@ -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.
Quoted 37 lines · Stefan Beller
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_usedinitialized, as we'd havecount > 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 <[email protected]>--- t/helper/test-lazy-init-name-hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)t/helper/test-lazy-init-name-hash.c +0
-0
t/helper/test-lazy-init-name-hash.c static void analyze_run(void) · line 117
Quoted 7 lines
t/helper/test-lazy-init-name-hash.c +1
-1@@ -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.
PATCH 1/1 t/helper/test-lazy-name-hash: fix compilation
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'.
---
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(-)
t/helper/test-lazy-init-name-hash.c +1 -1
@@ -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;
Signature · 1 line
2.15.1.620.gb9897f4670-goog
Quoted 23 lines · Stefan Beller
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'.
Quoted 7 lines
Acked-by Jonathan Tan <[email protected]>Signed-off-by Jeff Hostetler <[email protected]>Signed-off-by Stefan Beller <[email protected]>---
Slightly reworded the commit message. I'd really like this patch to be included such that I can compile git with the
DEVELOPER_CFLAGSflags.
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 ;-)
Quoted 16 lines
t/helper/test-lazy-init-name-hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)t/helper/test-lazy-init-name-hash.c +1
-1@@ -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;
Quoted 4 lines
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.
Quoted 7 lines · Stefan Beller
Quoted 4 lines
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.