Skip to content

Commit bfae342

Browse files
peffgitster
authored andcommitted
remote-testsvn: fix unitialized variable
In remote-test-svn, there is a parse_rev_note function to parse lines of the form "Revision-number" from notes. If it finds such a line and parses it, it returns 0, copying the value into a "struct rev_note". If it finds an entry that is garbled or out of range, it returns -1 to signal an error. However, if it does not find any "Revision-number" line at all, it returns success but does not put anything into the rev_note. So upon a successful return, the rev_note may or may not be initialized, and the caller has no way of knowing. gcc does not usually catch the use of the unitialized variable because the conditional assignment happens in a separate function from the point of use. However, when compiling with -O3, gcc will inline parse_rev_note and notice the problem. We can fix it by returning "-1" when no note is found (so on a zero return, we always found a valid value). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 790c83c commit bfae342

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

remote-testsvn.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ static int parse_rev_note(const char *msg, struct rev_note *res)
9090
if (end == value || i < 0 || i > UINT32_MAX)
9191
return -1;
9292
res->rev_nr = i;
93+
return 0;
9394
}
9495
msg += len + 1;
9596
}
96-
return 0;
97+
/* didn't find it */
98+
return -1;
9799
}
98100

99101
static int note2mark_cb(const unsigned char *object_sha1,

0 commit comments

Comments
 (0)