Commit 2e1e0f10 by Vicent Marti

blame: Do not assume blob contents are NULL-terminated

parent 1ba48b7c
......@@ -38,6 +38,7 @@ static void parse_opts(struct opts *o, int argc, char *argv[]);
int main(int argc, char *argv[])
{
int i, line, break_on_null_hunk;
size_t rawsize;
char spec[1024] = {0};
struct opts o = {0};
const char *rawdata;
......@@ -94,23 +95,24 @@ int main(int argc, char *argv[])
git_object_free(obj);
rawdata = git_blob_rawcontent(blob);
rawsize = git_blob_rawsize(blob);
/** Produce the output. */
line = 1;
i = 0;
break_on_null_hunk = 0;
while (i < git_blob_rawsize(blob)) {
const char *eol = strchr(rawdata+i, '\n');
while (i < rawsize) {
const char *eol = memchr(rawdata + i, '\n', rawsize - i);
char oid[10] = {0};
const git_blame_hunk *hunk = git_blame_get_hunk_byline(blame, line);
if (break_on_null_hunk && !hunk) break;
if (break_on_null_hunk && !hunk)
break;
if (hunk) {
char sig[128] = {0};
break_on_null_hunk = 1;
git_oid_tostr(oid, 10, &hunk->final_commit_id);
snprintf(sig, 30, "%s <%s>", hunk->final_signature->name, hunk->final_signature->email);
......@@ -118,8 +120,8 @@ int main(int argc, char *argv[])
oid,
sig,
line,
(int)(eol-rawdata-i),
rawdata+i);
(int)(eol - rawdata - i),
rawdata + i);
}
i = (int)(eol - rawdata + 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment