Skip to content

Commit 7e6b96c

Browse files
peffgitster
authored andcommitted
test-read-cache: drop namelen variable
Early in the function we set "namelen = strlen(name)" if "name" is non-NULL. Later, we use "namelen" only if "name" is non-NULL. However, it's hard to immediately see this, and it seems to confuse gcc 9.2.1 (with "-flto" interestingly, though all of the involved logic is in inline functions; it also triggers when building with ASan). Let's simplify the code and remove the variable entirely. There's only one use of namelen anyway, so we can just call strlen() then. It's true this is in a loop, so we might execute strlen() more often. But: - this is test code that only ever loops twice in our test suite (we do loop 1000 times in a t/perf test, but without using this option). - a decent compiler ought to be able to hoist that out of the loop anyway (though I wouldn't count on gcc 9.2.1 doing so!) Reported-by: Stephan Beyer <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4b3690 commit 7e6b96c

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

t/helper/test-read-cache.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
int cmd__read_cache(int argc, const char **argv)
66
{
7-
int i, cnt = 1, namelen;
7+
int i, cnt = 1;
88
const char *name = NULL;
99

1010
if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
11-
namelen = strlen(name);
1211
argc--;
1312
argv++;
1413
}
@@ -24,7 +23,7 @@ int cmd__read_cache(int argc, const char **argv)
2423

2524
refresh_index(&the_index, REFRESH_QUIET,
2625
NULL, NULL, NULL);
27-
pos = index_name_pos(&the_index, name, namelen);
26+
pos = index_name_pos(&the_index, name, strlen(name));
2827
if (pos < 0)
2928
die("%s not in index", name);
3029
printf("%s is%s up to date\n", name,

0 commit comments

Comments
 (0)