[PATCH] remote: initialize values that might not be set

Subsystems: the rest

STALE1889d

2 messages, 2 authors, 2021-06-07 · open the first message on its own page

[PATCH] remote: initialize values that might not be set

From: Derrick Stolee via GitGitGadget <hidden>
Date: 2021-06-07 12:39:45

From: Derrick Stolee <redacted>

I noticed during an unrelated test with Valgrind that these variables
might be left un-set by stat_tracking_info() in some cases. Initialize
them so that a later branch upon their value is consistent.

Signed-off-by: Derrick Stolee <redacted>
---
    remote: initialize values that might not be set
    
    A very minor fixup.
    
    Thanks, -Stolee

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-974%2Fderrickstolee%2Fremote-uninitialized-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-974/derrickstolee/remote-uninitialized-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/974

 remote.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/remote.c b/remote.c
index c3f85c17ca7c..a116392fb057 100644
--- a/remote.c
+++ b/remote.c
@@ -2101,7 +2101,7 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
 int format_tracking_info(struct branch *branch, struct strbuf *sb,
 			 enum ahead_behind_flags abf)
 {
-	int ours, theirs, sti;
+	int ours = 0, theirs = 0, sti = 0;
 	const char *full_base;
 	char *base;
 	int upstream_is_gone = 0;
base-commit: 71ca53e8125e36efbda17293c50027d31681a41f
-- 
gitgitgadget

Re: [PATCH] remote: initialize values that might not be set

From: Johannes Schindelin <hidden>
Date: 2021-06-07 21:59:25

Hi Stolee,

On Mon, 7 Jun 2021, Derrick Stolee via GitGitGadget wrote:
quoted hunk
From: Derrick Stolee <redacted>

I noticed during an unrelated test with Valgrind that these variables
might be left un-set by stat_tracking_info() in some cases. Initialize
them so that a later branch upon their value is consistent.

Signed-off-by: Derrick Stolee <redacted>
---
    remote: initialize values that might not be set

    A very minor fixup.

    Thanks, -Stolee

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-974%2Fderrickstolee%2Fremote-uninitialized-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-974/derrickstolee/remote-uninitialized-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/974

 remote.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/remote.c b/remote.c
index c3f85c17ca7c..a116392fb057 100644
--- a/remote.c
+++ b/remote.c
@@ -2101,7 +2101,7 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
 int format_tracking_info(struct branch *branch, struct strbuf *sb,
 			 enum ahead_behind_flags abf)
 {
-	int ours, theirs, sti;
+	int ours = 0, theirs = 0, sti = 0;
While I like this change, I am somewhat confused where the values are used
for branching. The only time I see them used when `stat_branch_pair()` has
_not_ initialized `ours` and `theirs` is in those `trace2_data_intmax()`
calls. Otherwise `sti` is set to -1 and the other users of `ours` and
`theirs` aren't reached.

If my reading of the code is correct, maybe the commit message could be
adjusted to talk about tracing instead of branching?

Thanks,
Dscho
 	const char *full_base;
 	char *base;
 	int upstream_is_gone = 0;

base-commit: 71ca53e8125e36efbda17293c50027d31681a41f
--
gitgitgadget
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help