Skip to content

Instantly share code, notes, and snippets.

@Merovius
Last active December 17, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Merovius/5624157 to your computer and use it in GitHub Desktop.
Save Merovius/5624157 to your computer and use it in GitHub Desktop.
git_shorten_add segfaults when adding to many objects.
#0 0x00007ffff7b55d18 in push_leaf (os=0x6011f0, idx=32767, push_at=10,
oid=0x7fffffffdebb "fb1970fb98c05d1fc75a21cc9b977") at /home/mero/src/libgit2/src/oid.c:279
node = 0x7ffff6588ff0
leaf = 0x7ffff6389010
idx_leaf = -32768
#1 0x00007ffff7b55edc in git_oid_shorten_add (os=0x6011f0,
text_oid=0x7fffffffdeb0 "d8f11d9ac1afb1970fb98c05d1fc75a21cc9b977")
at /home/mero/src/libgit2/src/oid.c:388
tail = 0x7fffffffdeba "afb1970fb98c05d1fc75a21cc9b977"
c = 10
node = 0x7ffff7f06ff0
i = 10
is_leaf = true
idx = 32767
#2 0x00000000004009ae in odb_foreach_cb (id=0x7ffff7fde078, payload=0x6011f0) at test.c:13
s = 0x6011f0
sid = "d8f11d9ac1afb1970fb98c05d1fc75a21cc9b977"
#3 0x00007ffff7b43daa in git_pack_foreach_entry (p=0x60b2a0, cb=0x40096c <odb_foreach_cb>,
data=0x6011f0) at /home/mero/src/libgit2/src/pack.c:1041
index = 0x7ffff7fdc408 ""
current = 0x7ffff7fdf2f8 ""
i = 253
__PRETTY_FUNCTION__ = "git_pack_foreach_entry"
#4 0x00007ffff7b34fa5 in pack_backend__foreach (_backend=0x601670, cb=0x40096c <odb_foreach_cb>,
data=0x6011f0) at /home/mero/src/libgit2/src/odb_pack.c:443
error = 0
p = 0x60b2a0
backend = 0x601670
i = 7
__PRETTY_FUNCTION__ = "pack_backend__foreach"
#5 0x00007ffff7b753cc in git_odb_foreach (db=0x602900, cb=0x40096c <odb_foreach_cb>,
payload=0x6011f0) at /home/mero/src/libgit2/src/odb.c:819
b = 0x601670
error = 0
i = 1
internal = 0x601720
#6 0x0000000000400aee in main (argc=2, argv=0x7fffffffe168) at test.c:44
repo = 0x6010b0
db = 0x602900
s = 0x6011f0
#include <git2.h>
#include <stdio.h>
#include <stdlib.h>
int odb_foreach_cb(const git_oid *id, void *payload) {
git_oid_shorten *s = (git_oid_shorten *)payload;
char sid[41];
sid[40] = '\0';
git_oid_fmt(sid, id);
if (git_oid_shorten_add(s, sid) < 0) {
fprintf(stderr, "shorten_add\n");
return -1;
}
return 0;
}
int main(int argc, char **argv) {
if (argc < 2) {
fprintf(stderr, "Usage: %s path\n", argv[0]);
return 1;
}
git_repository *repo;
if (git_repository_open(&repo, argv[1])) {
fprintf(stderr, "Could not open repo\n");
return 1;
}
git_odb *db;
if (git_repository_odb(&db, repo)) {
fprintf(stderr, "Could not open odb\n");
return 1;
}
git_oid_shorten *s = git_oid_shorten_new(4);
if (s == NULL) {
fprintf(stderr, "OOM\n");
return 1;
}
if (git_odb_foreach(db, &odb_foreach_cb, (void *)s)) {
fprintf(stderr, "foreach\n");
return 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment