Subject: Re: t1450-fsck (sometimes/often) failes on Mac OS X

From: Thomas Rast <[email-masked]>
Date: Sat, 28 Jul 2012 18:00:52 +0200

Heiko Voigt <[email-masked]> writes:

>         if (!git_index_file) {
> -               git_index_file = xmalloc(strlen(git_dir) + 7);
> +               git_index_file = xmalloc(strlen(git_dir) + 7 + 8);
>                 sprintf(git_index_file, "%s/index", git_dir);
>         }
[...]
> -       if (!memcmp(ent->base, objdir, pfxlen)) {
> +       objdirlen = strlen(objdir);
> +       if (!memcmp(ent->base, objdir, pfxlen > objdirlen ? objdirlen : pfxlen)) {
[...]
> Initialized empty Git repository in /Users/hvoigt/Repository/git/t/trash directory.t1450-fsck/another/.git/
> ==42686== Invalid read of size 8
> ==42686==    at 0x100625064: bcmp (in /usr/lib/libSystem.B.dylib)
> ==42686==    by 0x100112846: link_alt_odb_entries (in /Users/hvoigt/Repository/git/t/valgrind/../../git)
> ==42686==    by 0x1001129C0: read_info_alternates (in /Users/hvoigt/Repository/git/t/valgrind/../../git)
[...]
> ==42686==  Address 0x100faca78 is 8 bytes inside a block of size 13 alloc'd
> ==42686==    at 0x10029C679: malloc (vg_replace_malloc.c:266)
> ==42686==    by 0x1001349CD: xmalloc (in /Users/hvoigt/Repository/git/t/valgrind/../../git)
> ==42686==    by 0x1000C23F5: setup_git_env (in /Users/hvoigt/Repository/git/t/valgrind/../../git)

To me that looks just like a false positive.  memcmp (which seems to be
the same as bcmp) can load 8 bytes from an aligned address even if these
are only partially within the block being compared, since an aligned
load can never partially fault (it must all be within the same page).
Valgrind normally substitutes its own routines for memcmp etc. to
correctly handle this, but this does not seem to happen in your case for
some reason.

Then again I am not entirely sure how you could verify that this theory
is correct :-)

-- 
Thomas Rast
trast@{inf,student}.ethz.ch