diff options
author | Ben Straub <bs@github.com> | 2013-10-09 16:07:36 -0700 |
---|---|---|
committer | Ben Straub <bs@github.com> | 2013-10-09 16:07:36 -0700 |
commit | 2ccc84d2efaf8adf4886cfc42d8bd16e2ba98188 (patch) | |
tree | 3af43f1ac6d0c39c7d03707b93d20fd4b06486d6 /examples | |
parent | cb45dafaf85053c6ff4f3e8ac86f8b9cbc174033 (diff) | |
download | libgit2-2ccc84d2efaf8adf4886cfc42d8bd16e2ba98188.tar.gz |
Allow null bytes in blob
Diffstat (limited to 'examples')
-rw-r--r-- | examples/blame.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/examples/blame.c b/examples/blame.c index 88bdb7c76..5efb19930 100644 --- a/examples/blame.c +++ b/examples/blame.c @@ -29,7 +29,7 @@ static void usage(const char *msg, const char *arg) int main(int argc, char *argv[]) { - int i; + int i, line; char *path = NULL, *a; const char *rawdata, *commitspec=NULL; git_repository *repo = NULL; @@ -99,11 +99,12 @@ int main(int argc, char *argv[]) rawdata = git_blob_rawcontent(blob); /* Produce the output */ - i = 1; - while (rawdata[0]) { - const char *eol = strchr(rawdata, '\n'); + line = 1; + i = 0; + while (i < git_blob_rawsize(blob)) { + const char *eol = strchr(rawdata+i, '\n'); char oid[10] = {0}; - const git_blame_hunk *hunk = git_blame_get_hunk_byline(blame, i); + const git_blame_hunk *hunk = git_blame_get_hunk_byline(blame, line); git_commit *hunkcommit; const git_signature *sig; @@ -114,13 +115,13 @@ int main(int argc, char *argv[]) printf("%s ( %-30s %3d) %.*s\n", oid, sig->name, - i, - (int)(eol-rawdata), - rawdata); + line, + (int)(eol-rawdata-i), + rawdata+i); git_commit_free(hunkcommit); - rawdata = eol+1; - i++; + i = eol - rawdata + 1; + line++; } /* Cleanup */ |