From: David Turner <dturner@twopensource.com>
To: karthik nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/2] sha1_file: Add sha1_object_type_literally and export it.
Date: Wed, 25 Feb 2015 15:15:52 -0500 [thread overview]
Message-ID: <1424895352.2968.8.camel@leckie> (raw)
In-Reply-To: <54EE29AD.4060802@gmail.com>
On Thu, 2015-02-26 at 01:29 +0530, karthik nayak wrote:
>
> On 02/25/2015 11:52 PM, David Turner wrote:
> > On Wed, 2015-02-25 at 16:37 +0530, Karthik Nayak wrote:
> >> + unsigned long mapsize;
> >> ...
> >> + map = map_sha1_file(sha1, &mapsize);
> >
> > I know this is a pre-existing issue, but I'm not sure "unsigned long" is
> > the right type here. Shouldn't it be a size_t?
> I got the type from the function definition of map_sha1_file(), which is
> "void *map_sha1_file(const unsigned char *sha1, unsigned long *size)"
Yep. That's why I describe it as a pre-existing issue - it's not your
fault that the type is funny. But it might be worth cleaning up while
you're in here. Or it might not -- maybe I'm totally off base and the
type is correct.
> >
> >> + if (!map)
> >> + return -1;
> >> + if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
> >> + status = error("unable to unpack %s header",
> >> + sha1_to_hex(sha1));
> >> +
> >> + for (i = 0; i < 32; i++) {
> >
> > This number should probably be a constant.
> Do you want me to define it as a preprocessor directive?
Sounds good to me.
> >> + if (hdr[i] == ' ') {
> >> + type[i] = '\0';
> >> + break;
> >> + }
> >> + type[i] = hdr[i];
> >> + }
> >
> > type might end up without a trailing \0 here in the case where hdr has
> > no space in it. Is this possible?
> What's possible is when the object type name is greater than 32bytes
> "hdr" will not be able to hold the whole type, its a tradeoff, I guess I
> should put a null terminator at the end of "hdr". What do you suggest?
Is it an error for the object type name to be > 32 bytes? If there is
no max length, then maybe you should use the strbuf API for this.
Silently truncating is probably the wrong thing to do, and leaving it
unterminated is dangerous unless callers know how to handle that case.
If it is an error, then you should return an error code.
next prev parent reply other threads:[~2015-02-25 20:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-25 11:06 [PATCH 0/2] cat-file --literally karthik nayak
2015-02-25 11:07 ` [PATCH 1/2] sha1_file: Add sha1_object_type_literally and export it Karthik Nayak
2015-02-25 18:22 ` David Turner
2015-02-25 19:59 ` karthik nayak
2015-02-25 20:15 ` David Turner [this message]
2015-02-25 21:32 ` Junio C Hamano
2015-02-25 22:44 ` Junio C Hamano
2015-02-25 21:55 ` Eric Sunshine
2015-02-26 15:07 ` Karthik Nayak
2015-02-25 11:08 ` [PATCH 2/2] cat-file: add --literally option Karthik Nayak
2015-02-25 22:14 ` Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1424895352.2968.8.camel@leckie \
--to=dturner@twopensource.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).