[PATCH 1/5] convert: initialize attr_action in convert_attrs
- From
- Martin Ågren <martin.agren@gmail.com>
- Date
- Aug 15, 2017, 12:53 UTC
- Message-ID
- <0fd7f3184d285df8867ea44dd1adf418ebfc5ef3.1502780344.git.martin.agren@gmail.com>
- In-Reply-To
- <cover.1502780343.git.martin.agren@gmail.com>
convert_attrs populates a struct conv_attrs. The field attr_action is not set in all code paths, but still one caller unconditionally reads it. Since git_check_attr always returns the same value, we'll always end up in the same code path and there is no problem right now. But convert_attrs is obviously trying not to rely on such an implementation-detail of another component.
Initialize attr_action to CRLF_UNDEFINED in the dead code path.
Actually, in the code path that /is/ taken, the variable is assigned to twice and the first assignment has no effect. That's not wrong, but let's remove that first assignment while we're here.
Signed-off-by: Martin Ågren <martin.agren@gmail.com> --- I hit a warning about attr_action possibly being uninitialized when building with SANITIZE=thread. I guess it's some random interaction between code added by tsan, the optimizer (-O3) and the warning machinery. (This was with gcc 5.4.0.)
convert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/convert.c b/convert.c index 1012462e3..943d957b4 100644 --- a/convert.c +++ b/convert.c @@ -1040,7 +1040,6 @@ static void convert_attrs(struct conv_attrs *ca, const char *path) ca->crlf_action = git_path_check_crlf(ccheck + 4); if (ca->crlf_action == CRLF_UNDEFINED) ca->crlf_action = git_path_check_crlf(ccheck + 0); - ca->attr_action = ca->crlf_action; ca->ident = git_path_check_ident(ccheck + 1); ca->drv = git_path_check_convert(ccheck + 2); if (ca->crlf_action != CRLF_BINARY) { @@ -1058,6 +1057,7 @@ static void convert_attrs(struct conv_attrs *ca, const char *path) } else { ca->drv = NULL; ca->crlf_action = CRLF_UNDEFINED; + ca->attr_action = CRLF_UNDEFINED; ca->ident = 0; } if (ca->crlf_action == CRLF_TEXT)
-- 2.14.1.151.gdfeca7a7e