Allow null bytes in blob
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
diff --git a/examples/blame.c b/examples/blame.c
index 88bdb7c..5efb199 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 */