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

Re: [PATCH v7 1/4] sha1_file.c: support reading from a loose object of unknown type

From
karthik nayak <karthik.188@gmail.com>
Date
Apr 4, 2015, 19:53 UTC
Message-ID
<55204141.9070100@gmail.com>
In-Reply-To
<xmqq7ftrg02b.fsf@gitster.dls.corp.google.com>
On 04/05/2015 01:04 AM, Junio C Hamano wrote:
Show 38 quoted lines
> Karthik Nayak <karthik.188@gmail.com> writes:
>
> > @@ -2586,13 +2649,15 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
> >               *(oi->disk_sizep) = 0;
> >           if (oi->delta_base_sha1)
> >               hashclr(oi->delta_base_sha1);
> > +        if (oi->typename)
> > +            strbuf_addstr(oi->typename, typename(co->type));
> >           oi->whence = OI_CACHED;
> >           return 0;
> >       }
>
> Just before the pre-context of this hunk, there is this bit:
>
>     if (oi->typep)
>         *(oi->typep) = co->type;
>
> which tells me that the callers of this function is allowed to pass
> a NULL in oi->typep when they are not interested in the type of the
> object.
>
> >       if (!find_pack_entry(real, &e)) {
> >           /* Most likely it's a loose object. */
> > -        if (!sha1_loose_object_info(real, oi)) {
> > +        if (!sha1_loose_object_info(real, oi, flags)) {
> >               oi->whence = OI_LOOSE;
> >               return 0;
> >           }
> > @@ -2616,6 +2681,8 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
> >           oi->u.packed.is_delta = (rtype == OBJ_REF_DELTA ||
> >                        rtype == OBJ_OFS_DELTA);
> >       }
> > +    if (oi->typename)
> > +        strbuf_addstr(oi->typename, typename(*oi->typep));
>
> So, it makes me wonder what guarantee we have that this does not
> dereference a NULL here.
>

As per my code, oi->typename is only pointing to something when oi->typep is ( As oi->typename is currently only used in cat-file.c). But what you're saying also is true, there is no other guarantee, as a user may set oi->typename to point to a struct strbuf and leave out oi->typep.

  if (oi->typename && oi->typep)
          strbuf_addstr(oi->typename, typename(*oi->typep));
This should suffice. Do you want me to re-roll this?
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 19 in “cat-file: teach cat-file a '--literally' option”
  1. 0/4 cat-file: teach cat-file a '--literally' optionkarthik nayak, Apr 4, 2015
  2. 1/4 sha1_file.c: support reading from a loose object of unknown typeKarthik Nayak, Apr 4, 2015
  3. Junio C HamanoApr 4, 2015
  4. karthik nayakApr 4, 2015
  5. Junio C HamanoApr 5, 2015
  6. karthik nayakApr 5, 2015
  7. Junio C HamanoApr 5, 2015
  8. karthik nayakApr 7, 2015
  9. 1/4 sha1_file.c: support reading from a loose object of unknown typeKarthik Nayak, Apr 5, 2015
  10. Eric SunshineApr 7, 2015
  11. 2/4 cat-file: teach cat-file a '--literally' optionKarthik Nayak, Apr 4, 2015
  12. Eric SunshineApr 7, 2015
  13. 3/4 cat-file: add documentation for '--literally' option.Karthik Nayak, Apr 4, 2015
  14. Eric SunshineApr 7, 2015
  15. 4/4 t1006: add tests for git cat-file --literallyKarthik Nayak, Apr 4, 2015
  16. Eric SunshineApr 7, 2015
  17. karthik nayakApr 8, 2015
  18. Eric SunshineApr 8, 2015
  19. Karthik NayakApr 9, 2015

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.