Skip to content

git_index_entry* can't read path on ubuntu. #35

@chobie

Description

@chobie

im tring to use libgit2 on my ubuntu 10.10.
i found Segmentation fault when try to read git_index_entry->path.

git clone https://github.com/libgit2/libgit2.git
cd libgit2
./waf configure
./waf build-shared
sudo ./waf install-shared

cat > git_index_test.c <<EOF
#include <stdio.h>
#include <git2.h>

int main(int argc, char * args[])
{
    git_index_entry *entry;
    git_index *index;
    git_index_open_bare(&index,".git/index");

    git_index_read(index);
    git_index_entrycount(index);
    int offset = git_index_find(index,"README.md");

    entry = git_index_get(index,offset);

    printf("pointer_address: %d\n", entry->path);
    //Segmentation fault on my machine.
    printf("path: %s\n",entry->path);
    git_index_free(index);

    return 0;
}
EOF

gcc -lgit2 -o git_index_test git_index_test.c

./git_index_test
pointer_address: 9
Segmentation fault

I searched reason. but i couldn't understand.
git_index_entry->path readable in git_index_get(). but git_index_entry->path was wrong address in main.

(but ruggaed work well on my machine.probably i missunderstood something...)

Could you please advice me how to fix this probrem?

$ gcc -v
Using built-in specs.
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions