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

Re: [PATCH 2/2] fetch/push: readd rsync support

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 28, 2007, 09:30 UTC
Message-ID
<7v3awzqgqc.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<Pine.LNX.4.64.0709280606530.28395@racer.site>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 30 quoted lines
> +/*
> + * 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 ;-).
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 9 of 19 in “rsync support”
  1. 0/2 rsync supportJohannes Schindelin, Sep 28, 2007
  2. 1/2 Introduce remove_dir_recursively()Johannes Schindelin, Sep 28, 2007
  3. Junio C HamanoSep 28, 2007
  4. Johannes SchindelinSep 28, 2007
  5. David KastrupSep 28, 2007
  6. 2/2 fetch/push: readd rsync supportJohannes Schindelin, Sep 28, 2007
  7. Shawn O. PearceSep 28, 2007
  8. Johannes SchindelinSep 28, 2007
  9. Junio C HamanoSep 28, 2007
  10. Johannes SchindelinSep 28, 2007
  11. 0/2 rsync support, was Re: [PATCH 0/2] rsync supportJohannes Schindelin, Sep 28, 2007
  12. 1/2 Introduce remove_dir_recursively()Johannes Schindelin, Sep 28, 2007
  13. 2/2 fetch/push: readd rsync supportJohannes Schindelin, Sep 28, 2007
  14. Johannes SchindelinSep 28, 2007
  15. Junio C HamanoSep 28, 2007
  16. Johannes SchindelinSep 28, 2007
  17. 2/2 fetch/push: readd rsync supportJohannes Schindelin, Sep 29, 2007
  18. Junio C HamanoSep 30, 2007
  19. Johannes SchindelinSep 30, 2007

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.