git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 06/11] sparse-checkout: avoid using internal API of unpack-trees, take 2

From
Elijah Newren <newren@gmail.com>
Date
Feb 25, 2023, 00:40 UTC
Message-ID
<CABPp-BEbZZjAE8N4OgWMEiV=MpGhEef0G4zytTTwrEjpGq0Qfw@mail.gmail.com>
In-Reply-To
<20230224232256.2038749-1-jonathantanmy@google.com>
On Fri, Feb 24, 2023 at 3:22 PM Jonathan Tan <jonathantanmy@google.com> wrote:
Show 45 quoted lines
>
> "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
> > From: Elijah Newren <newren@gmail.com>
> >
> > Commit 2f6b1eb794 ("cache API: add a "INDEX_STATE_INIT" macro/function,
> > add release_index()", 2023-01-12) mistakenly added some initialization
> > of a member of unpack_trees_options that was intended to be
> > internal-only.  Further, it served no purpose as it simply duplicated
> > the initialization that unpack-trees.c code was already doing.
> >
> > Signed-off-by: Elijah Newren <newren@gmail.com>
> > ---
> >  builtin/sparse-checkout.c | 1 -
> >  1 file changed, 1 deletion(-)
> >
> > diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
> > index 4b7390ce367..8d5ae6f2a60 100644
> > --- a/builtin/sparse-checkout.c
> > +++ b/builtin/sparse-checkout.c
> > @@ -217,7 +217,6 @@ static int update_working_directory(struct pattern_list *pl)
> >       o.head_idx = -1;
> >       o.src_index = r->index;
> >       o.dst_index = r->index;
> > -     index_state_init(&o.result, r);
> >       o.skip_sparse_checkout = 0;
> >
> >       setup_work_tree();
>
> The commit message seems to imply that in this code path, there is some
> code in unpack-trees.c that runs index_state_init(), but that doesn't
> seem to be the case. memset-ting the result field with a junk value
> causes valgrind to fail with the following trace:
>
>   ==2035705== Invalid read of size 8
>   ==2035705==    at 0x30D982: lazy_init_name_hash (name-hash.c:602)
>   ==2035705==    by 0x30DDDA: index_file_exists (name-hash.c:721)
>   ==2035705==    by 0x3F71A8: check_ok_to_remove (unpack-trees.c:2430)
>   ==2035705==    by 0x3F74EE: verify_absent_1 (unpack-trees.c:2495)
>   ==2035705==    by 0x3F75C6: verify_absent_sparse (unpack-trees.c:2523)
>   ==2035705==    by 0x3F2A15: apply_sparse_checkout (unpack-trees.c:566)
>   ==2035705==    by 0x3F6849: update_sparsity (unpack-trees.c:2147)
>   ==2035705==    by 0x1FC105: update_working_directory (sparse-checkout.c:228)
>
> so it might be better to move the init invocation to update_sparsity()
> instead of only removing it.

Actually, my commit message was implying o->result is only used by unpack_trees() and not update_sparsity(). While that implication is *mostly* true, I forgot about check_ok_to_remove(). Doh!

Thanks for reviewing so carefully; I'll move the initialization to update_sparsity() instead.

Previous: Jonathan TanNext: Elijah Newren via GitGitGadget
Message 16 of 57 in “Clarify API for dir.[ch] and unpack-trees.[ch] -- mark relevant fields as internal”
  1. 00/11 Clarify API for dir.[ch] and unpack-trees.[ch] -- mark relevant fields as internalElijah Newren via GitGitGadget, Feb 23, 2023
  2. 01/11 dir: separate public from internal portion of dir_structElijah Newren via GitGitGadget, Feb 23, 2023
  3. 02/11 dir: add a usage note to exclude_per_dirElijah Newren via GitGitGadget, Feb 23, 2023
  4. Jonathan TanFeb 24, 2023
  5. Elijah NewrenFeb 25, 2023
  6. Jonathan TanFeb 25, 2023
  7. Elijah NewrenFeb 25, 2023
  8. 03/11 dir: mark output only fields of dir_struct as suchElijah Newren via GitGitGadget, Feb 23, 2023
  9. 04/11 unpack-trees: clean up some flow controlElijah Newren via GitGitGadget, Feb 23, 2023
  10. Jonathan TanFeb 24, 2023
  11. 05/11 sparse-checkout: avoid using internal API of unpack-treesElijah Newren via GitGitGadget, Feb 23, 2023
  12. Jonathan TanFeb 24, 2023
  13. Elijah NewrenFeb 25, 2023
  14. 06/11 sparse-checkout: avoid using internal API of unpack-trees, take 2Elijah Newren via GitGitGadget, Feb 23, 2023
  15. Jonathan TanFeb 24, 2023
  16. Elijah NewrenFeb 25, 2023
  17. 07/11 unpack_trees: start splitting internal fields from public APIElijah Newren via GitGitGadget, Feb 23, 2023
  18. 09/11 unpack-trees: rewrap a few overlong lines from previous patchElijah Newren via GitGitGadget, Feb 23, 2023
  19. 10/11 unpack-trees: special case read-tree debugging as internal usageElijah Newren via GitGitGadget, Feb 23, 2023
  20. 08/11 unpack-trees: mark fields only used internally as internalElijah Newren via GitGitGadget, Feb 23, 2023
  21. 11/11 unpack-trees: add usage notices around df_conflict_entryElijah Newren via GitGitGadget, Feb 23, 2023
  22. Derrick StoleeFeb 23, 2023
  23. Derrick StoleeFeb 23, 2023
  24. Elijah NewrenFeb 23, 2023
  25. Elijah NewrenFeb 23, 2023
  26. Junio C HamanoFeb 24, 2023
  27. Jacob KellerFeb 24, 2023
  28. Jonathan TanFeb 24, 2023
  29. 00/11 Clarify API for dir.[ch] and unpack-trees.[ch] -- mark relevant fields as internalElijah Newren via GitGitGadget, Feb 25, 2023
  30. 02/11 dir: add a usage note to exclude_per_dirElijah Newren via GitGitGadget, Feb 25, 2023
  31. 01/11 dir: separate public from internal portion of dir_structElijah Newren via GitGitGadget, Feb 25, 2023
  32. 03/11 dir: mark output only fields of dir_struct as suchElijah Newren via GitGitGadget, Feb 25, 2023
  33. 04/11 unpack-trees: clean up some flow controlElijah Newren via GitGitGadget, Feb 25, 2023
  34. 05/11 sparse-checkout: avoid using internal API of unpack-treesElijah Newren via GitGitGadget, Feb 25, 2023
  35. 06/11 sparse-checkout: avoid using internal API of unpack-trees, take 2Elijah Newren via GitGitGadget, Feb 25, 2023
  36. 09/11 unpack-trees: rewrap a few overlong lines from previous patchElijah Newren via GitGitGadget, Feb 25, 2023
  37. 07/11 unpack_trees: start splitting internal fields from public APIElijah Newren via GitGitGadget, Feb 25, 2023
  38. 11/11 unpack-trees: add usage notices around df_conflict_entryElijah Newren via GitGitGadget, Feb 25, 2023
  39. 10/11 unpack-trees: special case read-tree debugging as internal usageElijah Newren via GitGitGadget, Feb 25, 2023
  40. 08/11 unpack-trees: mark fields only used internally as internalElijah Newren via GitGitGadget, Feb 25, 2023
  41. Junio C HamanoFeb 25, 2023
  42. 00/13 Clarify API for dir.[ch] and unpack-trees.[ch] -- mark relevant fields as internalElijah Newren via GitGitGadget, Feb 27, 2023
  43. 01/13 t2021: fix platform-specific leftover cruftElijah Newren via GitGitGadget, Feb 27, 2023
  44. Derrick StoleeFeb 27, 2023
  45. 02/13 unpack-trees: heed requests to overwrite ignored filesElijah Newren via GitGitGadget, Feb 27, 2023
  46. Jonathan TanFeb 27, 2023
  47. 03/13 dir: separate public from internal portion of dir_structElijah Newren via GitGitGadget, Feb 27, 2023
  48. 05/13 dir: mark output only fields of dir_struct as suchElijah Newren via GitGitGadget, Feb 27, 2023
  49. 04/13 dir: add a usage note to exclude_per_dirElijah Newren via GitGitGadget, Feb 27, 2023
  50. 07/13 sparse-checkout: avoid using internal API of unpack-treesElijah Newren via GitGitGadget, Feb 27, 2023
  51. 06/13 unpack-trees: clean up some flow controlElijah Newren via GitGitGadget, Feb 27, 2023
  52. 08/13 sparse-checkout: avoid using internal API of unpack-trees, take 2Elijah Newren via GitGitGadget, Feb 27, 2023
  53. 10/13 unpack-trees: mark fields only used internally as internalElijah Newren via GitGitGadget, Feb 27, 2023
  54. 09/13 unpack_trees: start splitting internal fields from public APIElijah Newren via GitGitGadget, Feb 27, 2023
  55. 11/13 unpack-trees: rewrap a few overlong lines from previous patchElijah Newren via GitGitGadget, Feb 27, 2023
  56. 12/13 unpack-trees: special case read-tree debugging as internal usageElijah Newren via GitGitGadget, Feb 27, 2023
  57. 13/13 unpack-trees: add usage notices around df_conflict_entryElijah Newren via GitGitGadget, Feb 27, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.