ls-files: don't try to prune an empty index
PATCH 1/1 ls-files: don't try to prune an empty index
Exit early when asked to prune an index that contains no entries to begin with. This avoids pointer arithmetic on istate->cache, which is possibly NULL in that case.
Found with Clang's UBSan.
--- builtin/ls-files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/ls-files.c +1 -1
@@ -362,7 +362,7 @@ static void prune_index(struct index_state *istate,int pos;unsigned int first, last; -if (!prefix) +if (!prefix || !istate->cache_nr)return ; pos =index_name_pos (istate, prefix, prefixlen);if (pos <0 )
Signature · 1 line
2.13.3
Quoted 16 lines · René Scharfe
Exit early when asked to prune an index that contains no entries to begin with. This avoids pointer arithmetic on
istate->cache, which is possibly NULL in that case.Found with Clang's UBSan.
Signed-off-by Rene Scharfe <[email protected]>--- builtin/ls-files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)builtin/ls-files.c +0
-0
builtin/ls-files.c static void prune_index(struct index_state *istate, · line 368
Quoted 8 lines
builtin/ls-files.c +1
-1@@ -362,7 +362,7 @@ static void prune_index(struct index_state *istate,int pos;unsigned int first, last; -if (!prefix) +if (!prefix || !istate->cache_nr)return ; pos =index_name_pos (istate, prefix, prefixlen);if (pos <0 )
My patch looked like:
- if (!prefix)
+ if (!prefix || !istate->cache || istate->cache_nr == 0)
... which is probably a bit 'belt-n-braces'. ;-)
ATB,
Ramsay Jones
Am 16.07.2017 um 02:28 schrieb Ramsay Jones:
Quoted 33 lines · René Scharfe
Quoted 16 lines
Exit early when asked to prune an index that contains no entries to begin with. This avoids pointer arithmetic on
istate->cache, which is possibly NULL in that case.Found with Clang's UBSan.
Signed-off-by Rene Scharfe <[email protected]>--- builtin/ls-files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)builtin/ls-files.c +0
-0builtin/ls-files.c static void prune_index(struct index_state *istate, · line 368
Quoted 8 lines
builtin/ls-files.c +1
-1@@ -362,7 +362,7 @@ static void prune_index(struct index_state *istate,int pos;unsigned int first, last; -if (!prefix) +if (!prefix || !istate->cache_nr)return ; pos =index_name_pos (istate, prefix, prefixlen);if (pos <0 )My patch looked like:
(quoted diff) +1
-1- if (!prefix) + if (!prefix || !istate->cache || istate->cache_nr == 0)
Quoted 1 line
... which is probably a bit 'belt-n-braces'. ;-)
Not checking for !istate->cache at this point is a good thing, I think. If we have entries, then ->cache must not be NULL, and if it is we'd get a segfault, notifying us that we have a bug. We could add an assert to state this requirement explicitly, but that would be the topic of a different patch.
René
Quoted 5 lines · René Scharfe
Exit early when asked to prune an index that contains no entries to begin with. This avoids pointer arithmetic on
istate->cache, which is possibly NULL in that case.Found with Clang's UBSan.
Makes sense. We could use MOVE_ARRAY() here, but this is a sensible short-circuit to the whole function.
Looks like a good solution.
builtin/ls-files.c static void prune_index(struct index_state *istate, · line 368
Quoted 13 lines
builtin/ls-files.c +1
-1@@ -362,7 +362,7 @@ static void prune_index(struct index_state *istate,int pos;unsigned int first, last; -if (!prefix) +if (!prefix || !istate->cache_nr)return ; pos =index_name_pos (istate, prefix, prefixlen);if (pos <0 )
"git am" complained that this does not apply to its blobs. Did you hand-edit?
-Peff
Am 16.07.2017 um 12:41 schrieb Jeff King:
Quoted 21 lines · René Scharfe
Quoted 6 lines
Exit early when asked to prune an index that contains no entries to begin with. This avoids pointer arithmetic on
istate->cache, which is possibly NULL in that case.Found with Clang's UBSan.
Makes sense. We could use
MOVE_ARRAY()here, but this is a sensible short-circuit to the whole function.Looks like a good solution.
Quoted 8 lines
builtin/ls-files.c +0
-0@@ -362,7 +362,7 @@ static void prune_index(struct index_state *istate,int pos;unsigned int first, last;
Quoted 8 lines
builtin/ls-files.c static void prune_index(struct index_state *istate, · line 368
Quoted 5 lines
builtin/ls-files.c +1
-1-if (!prefix) +if (!prefix || !istate->cache_nr)return ; pos =index_name_pos (istate, prefix, prefixlen);if (pos <0 )"git am" complained that this does not apply to its blobs. Did you hand-edit?
I didn't, but perhaps I messed up the order of patches? MOVE_ARRAY patch 2 touches the same file, but I wouldn't expect the two changes to conflict. So not sure what's going on.
René
Quoted 17 lines · René Scharfe
Quoted 8 lines
Quoted 8 lines
builtin/ls-files.c +0
-0@@ -362,7 +362,7 @@ static void prune_index(struct index_state *istate,int pos;unsigned int first, last;Quoted 8 lines
builtin/ls-files.c static void prune_index(struct index_state *istate, · line 368
Quoted 5 lines
builtin/ls-files.c +1
-1-if (!prefix) +if (!prefix || !istate->cache_nr)return ; pos =index_name_pos (istate, prefix, prefixlen);if (pos <0 )"git am" complained that this does not apply to its blobs. Did you hand-edit?
Quoted 3 lines
I didn't, but perhaps I messed up the order of patches?
MOVE_ARRAYpatch 2 touches the same file, but I wouldn't expect the two changes to conflict. So not sure what's going on.
For some reason there's an extra space before the tab on each of the context lines. MUA issue or cut-and-paste, maybe?
-Peff
PATCH 1/1 ls-files: don't try to prune an empty index
In reply to René ScharfeExit early when asked to prune an index that contains no entries to begin with. This avoids pointer arithmetic on istate->cache, which is possibly NULL in that case.
Found with Clang's UBSan.
---
Messed up whitespace when sending this the first time.
builtin/ls-files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/ls-files.c +1 -1
@@ -362,7 +362,7 @@ static void prune_index(struct index_state *istate,int pos;unsigned int first, last; -if (!prefix) +if (!prefix || !istate->cache_nr)return ; pos =index_name_pos (istate, prefix, prefixlen);if (pos <0 )
Signature · 1 line
2.13.3
Am 16.07.2017 um 13:08 schrieb Jeff King:
Quoted 19 lines · René Scharfe
Quoted 18 lines
Quoted 17 lines
Quoted 6 lines
builtin/ls-files.c +0
-0builtin/ls-files.c static void prune_index(struct index_state *istate, · line 368
Quoted 8 lines
builtin/ls-files.c +1
-1@@ -362,7 +362,7 @@ static void prune_index(struct index_state *istate,int pos;unsigned int first, last; -if (!prefix) +if (!prefix || !istate->cache_nr)return ; pos =index_name_pos (istate, prefix, prefixlen);if (pos <0 )"git am" complained that this does not apply to its blobs. Did you hand-edit?
Quoted 6 lines
Quoted 3 lines
I didn't, but perhaps I messed up the order of patches?
MOVE_ARRAYpatch 2 touches the same file, but I wouldn't expect the two changes to conflict. So not sure what's going on.For some reason there's an extra space before the tab on each of the context lines. MUA issue or cut-and-paste, maybe?
That's possible. Will resend.
Am 16.07.2017 um 13:15 schrieb René Scharfe:
Quoted 21 lines
Am 16.07.2017 um 13:08 schrieb Jeff King:
Quoted 20 lines · René Scharfe
Quoted 19 lines
Quoted 18 lines
Quoted 14 lines
builtin/ls-files.c +1
-1@@ -362,7 +362,7 @@ static void prune_index(struct index_state *istate, int pos;unsigned int first, last; -if (!prefix) +if (!prefix || !istate->cache_nr)return ; pos =index_name_pos (istate, prefix, prefixlen);Quoted 1 line
if (pos < 0)"git am" complained that this does not apply to its blobs. Did you hand-edit?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I didn't, but perhaps I messed up the order of patches?
MOVE_ARRAYpatch 2 touches the same file, but I wouldn't expect the two changes to conflict. So not sure what's going on.For some reason there's an extra space before the tab on each of the context lines. MUA issue or cut-and-paste, maybe?
That's possible. Will resend.
... pressed Send to fast. Thanks for reporting the broken patch!
I use the extension Toggle Word Wrap with Thunderbird, but it wraps by default with no way to change that, so I forgot toggling this time. Grr, I've had enough of this! Went past the warranty warning and set mailnews.wraplength=0 now.
René