Skip to contentSkip to conversation

multi-pack-index: avoid dead store for struct progress

PATCH In review Carlo Marcelo Arenas Belón 3 participants 4 messages Oct 18, 2018 – Oct 19, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 multi-pack-index: avoid dead store for struct progress

it is initialized unconditionally by a call to start_progress below.

---
 midx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
midx.c +1 -1
index ea2f3ffe2e..4fac0cd08a 100644
@@ -941,7 +941,7 @@ static void midx_report(const char *fmt, ...)
 int verify_midx_file(const char *object_dir)
 {
 	uint32_t i;
-	struct progress *progress = NULL;
+	struct progress *progress;
 	struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
 	verify_midx_error = 0;
 
Signature · 1 line
2.19.1
#1 lore raw
Quoted 13 lines · Carlo Marcelo Arenas Belón

it is initialized unconditionally by a call to start_progress below.

---
  midx.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
midx.c +0 -0
index ea2f3ffe2e..4fac0cd08a 100644

midx.c static void midx_report(const char *fmt, ...) · line 947

Quoted 8 lines
midx.c +1 -1
@@ -941,7 +941,7 @@ static void midx_report(const char *fmt, ...)
  int verify_midx_file(const char *object_dir)
  {
  	uint32_t i;
-	struct progress *progress = NULL;
+	struct progress *progress;
  	struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
  	verify_midx_error = 0;
 

This makes sense as a cleanup. Is there a tool that reports a wasted initialization that you used to find this?

-Stolee

#2 lore raw
Quoted 3 lines · Derrick Stolee

Is there a tool that reports a wasted
initialization that you used to find this?

I'd used clang's analyzer recently to track a similar issue before in a different codebase, but not for this specific case.

Carlo

#3 lore raw
In reply to Carlo Marcelo Arenas Belón
Quoted 13 lines · Carlo Marcelo Arenas Belón

it is initialized unconditionally by a call to start_progress below.

---
 midx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
midx.c +0 -0
index ea2f3ffe2e..4fac0cd08a 100644

midx.c static void midx_report(const char *fmt, ...) · line 946

Quoted 7 lines
midx.c +1 -1
@@ -941,7 +941,7 @@ static void midx_report(const char *fmt, ...)
 int verify_midx_file(const char *object_dir)
 {
 	uint32_t i;
-	struct progress *progress = NULL;
+	struct progress *progress;
 	struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
 	verify_midx_error = 0;

Both changes make sense. It's kind of surprising that this still matters, though; I would have expected a compiler would notice.