git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Daniel Barkalow <barkalow@iabervon.org>, git@vger.kernel.org
Subject: Re: [PATCH 2/2] fetch/push: readd rsync support
Date: Fri, 28 Sep 2007 02:30:51 -0700	[thread overview]
Message-ID: <7v3awzqgqc.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0709280606530.28395@racer.site> (Johannes Schindelin's message of "Fri, 28 Sep 2007 06:07:19 +0100 (BST)")

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> +/*
> + * path is assumed to point to a buffer of PATH_MAX bytes, and
> + * path + name_offset is expected to point to "refs/".
> + */
> +
> +static int read_loose_refs(char *path, int name_offset, struct ref **tail)
> +{
> +	DIR *dir = opendir(path);
> +	struct dirent *de;
> +	struct {
> +		struct dirent *entries;
> +		int nr, alloc;
> +	} list;
> +	int i, pathlen;
> +
> +	if (!dir)
> +		return -1;
> +
> +	memset (&list, 0, sizeof(list));
> +
> +	while ((de = readdir(dir))) {
> +		if (de->d_name[0] == '.' && (de->d_name[1] == '\0' ||
> +				(de->d_name[1] == '.' &&
> +				 de->d_name[2] == '\0')))
> +			continue;
> +		if (list.nr >= list.alloc) {
> +			list.alloc = alloc_nr(list.nr);
> +			list.entries = xrealloc(list.entries,
> +				list.alloc * sizeof(*de));
> +		}

ALLOC_GROW() not applicable here?

> +		list.entries[list.nr++] = *de;

Are you sure about this?

The last paragraph in Rationale section, in

    http://www.opengroup.org/onlinepubs/000095399/basedefs/dirent.h.html

suggests that the d_name[] member in struct dirent could be
declared at the very end of the structure as length of 1 (the
traditional trick to implement a flex-array); your assignment
from *de into entries[] would not work as expected on such an
implementation.

On Linux with glibc it appears bits/dirent.h defines dirent with
"char d_name[256]", so you may not see a breakage there, though.

You only use a list of strings (char **), don't you?

> ...
> +			if (fd < 0)
> +				continue;
> +			next = alloc_ref(strlen(path + name_offset));

And as we discussed earlier you would need one more byte here ;-).

  parent reply	other threads:[~2007-09-28  9:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-28  5:06 [PATCH 0/2] rsync support Johannes Schindelin
2007-09-28  5:06 ` [PATCH 1/2] Introduce remove_dir_recursively() Johannes Schindelin
2007-09-28  9:05   ` Junio C Hamano
2007-09-28 12:35     ` Johannes Schindelin
2007-09-28 22:14       ` David Kastrup
2007-09-28  5:07 ` [PATCH 2/2] fetch/push: readd rsync support Johannes Schindelin
2007-09-28  5:20   ` Shawn O. Pearce
2007-09-28 12:22     ` Johannes Schindelin
2007-09-28  9:30   ` Junio C Hamano [this message]
2007-09-28 12:53     ` Johannes Schindelin
2007-09-28 15:28 ` [PATCH v2 0/2] rsync support, was Re: [PATCH 0/2] " Johannes Schindelin
2007-09-28 15:28 ` [PATCH v2 1/2] Introduce remove_dir_recursively() Johannes Schindelin
2007-09-28 15:29 ` [PATCH 2/2] fetch/push: readd rsync support Johannes Schindelin
2007-09-28 15:30   ` Johannes Schindelin
2007-09-28 21:20   ` Junio C Hamano
2007-09-28 22:48     ` Johannes Schindelin
2007-09-29  0:35     ` [PATCH v3 " Johannes Schindelin
2007-09-30  6:09       ` Junio C Hamano
2007-09-30 12:58         ` Johannes Schindelin

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=7v3awzqgqc.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=barkalow@iabervon.org \
    --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.
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).