Re: [PATCH v4 4/9] index-helper: new daemon for caching index and related stuff
- From
David Turner <dturner@twopensource.com>
- Date
- Nov 2, 2015, 22:14 UTC
- Message-ID
- <1446502451.4131.26.camel@twopensource.com>
- In-Reply-To
- <1446385369-8669-5-git-send-email-pclouds@gmail.com>
On Sun, 2015-11-01 at 14:42 +0100, Nguyễn Thái Ngọc Duy wrote:
Show 9 quoted lines
> + memcpy(new_mmap, istate->mmap, istate->mmap_size - 20); > + > + /* > + * The trailing hash must be written last after everything is > + * written. It's the indication that the shared memory is now > + * ready. > + */ > + hashcpy((unsigned char *)new_mmap + istate->mmap_size - 20, is->sha1); > +}
You need a memory barrier here. Otherwise, compilers may reorder these statements.
Show 13 quoted lines
> +#define SHM_PATH_LEN 72 /* we don't create very long paths.. */
> +
> +ssize_t git_shm_map(int oflag, int perm, ssize_t length, void **mmap,
> + int prot, int flags, const char *fmt, ...)
> +{
> + va_list ap;
> + char path[SHM_PATH_LEN];
> + int fd;
> +
> + path[0] = '/';
> + va_start(ap, fmt);
> + vsprintf(path + 1, fmt, ap);
> + va_end(ap);This would be safer with vsnprintf.