git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
To: "Clément Poulain" <clement.poulain@ensimag.imag.fr>
Cc: git@vger.kernel.org,
	Diane Gasselin <diane.gasselin@ensimag.imag.fr>,
	Axel Bonnet <axel.bonnet@ensimag.imag.fr>
Subject: Re: [PATCH v2 1/4] sha1_name: add get_sha1_with_context()
Date: Tue, 08 Jun 2010 19:57:58 +0200	[thread overview]
Message-ID: <vpqiq5t5rvd.fsf@bauges.imag.fr> (raw)
In-Reply-To: <1276004958-13540-2-git-send-email-clement.poulain@ensimag.imag.fr> ("Clément Poulain"'s message of "Tue\,  8 Jun 2010 15\:49\:15 +0200")

This patch produces uncompilable code for me:

cc1: warnings being treated as errors
In file included from builtin.h:6,
                 from fast-import.c:147:
cache.h: In function ‘get_sha1_with_context’:
cache.h:748: error: implicit declaration of function ‘get_sha1_with_context_1’

Forgot to add get_sha1_with_context_1 to cache.h?

Clément Poulain <clement.poulain@ensimag.imag.fr> writes:

> +struct object_context {
> +	unsigned char tree[20];
> +	char path[PATH_MAX];
> +	unsigned mode;
> +};
> +#define OBJECT_CONTEXT_INIT  { 0, 0, 0 }
> +

I'm not an expert in struct initializers, but after doing experiments
with GCC, this raises a warning

builtin/cat-file.c:90: error: missing braces around initializer
builtin/cat-file.c:90: error: (near initialization for ‘obj_context.tree’)

and the behavior is to flatten the arrays contained inside the
structure. So, your OBJECT_CONTEXT_INIT initializes the 3 first bytes
of tree to 0, and leaves other fields uninitialized.

You probably want something like this instead if you want to
initialize the whole struct:

{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, "", 0}

> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -933,8 +933,8 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
>   */
>  int get_sha1(const char *name, unsigned char *sha1)
>  {
> -	unsigned unused;
> -	return get_sha1_with_mode(name, sha1, &unused);
> +	struct object_context unused;
> +	return get_sha1_with_context(name, sha1, &unused);
>  }

This changes doesn't seem harmful, but it doesn't seem useful to me
either: get_sha1_with_mode still exists, right?

>  int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode, int gently, const char *prefix)
>  {
> +	struct object_context orc;

What does orc stand for? I understand "oc" for "object context", but
I'm curious about the r ;-).

> +		orc->path[sizeof(orc->path)] = '\0';
> +

Isn't this an off-by-one? The last element of an array of size N is
array[N-1] ...

> +			orc->path[sizeof(orc->path)] = '\0';

Same here.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

  parent reply	other threads:[~2010-06-08 17:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-08 13:49 [PATCH v2 0/4] git-gui blame: use textconv Clément Poulain
2010-06-08 13:49 ` [PATCH v2 1/4] sha1_name: add get_sha1_with_context() Clément Poulain
2010-06-08 13:49   ` [PATCH v2 2/4] textconv: support for cat_file Clément Poulain
2010-06-08 13:49     ` [PATCH v2 3/4] git gui: use textconv filter for diff and blame Clément Poulain
2010-06-08 13:49       ` [PATCH v2 4/4] t/t8007: test textconv support for cat-file Clément Poulain
2010-06-08 18:12     ` [PATCH v2 2/4] textconv: support for cat_file Matthieu Moy
2010-06-08 17:57   ` Matthieu Moy [this message]
2010-06-08 22:30     ` [PATCH v2 1/4] sha1_name: add get_sha1_with_context() Clément Poulain
2010-06-09  6:13       ` Jeff King
2010-06-09  7:29         ` Matthieu Moy

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=vpqiq5t5rvd.fsf@bauges.imag.fr \
    --to=matthieu.moy@grenoble-inp.fr \
    --cc=axel.bonnet@ensimag.imag.fr \
    --cc=clement.poulain@ensimag.imag.fr \
    --cc=diane.gasselin@ensimag.imag.fr \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).