Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
e0482934
Commit
e0482934
authored
Nov 21, 2014
by
Edward Thomson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2725 from libgit2/vmg/attr-null
Do not assume blob contents are NULL terminated
parents
6f446176
24cce239
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
19 deletions
+23
-19
examples/blame.c
+8
-6
src/attr_file.c
+4
-4
src/buf_text.c
+1
-0
src/buffer.c
+7
-4
src/notes.c
+1
-2
tests/core/buffer.c
+2
-3
No files found.
examples/blame.c
View file @
e0482934
...
...
@@ -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
);
...
...
src/attr_file.c
View file @
e0482934
...
...
@@ -103,7 +103,6 @@ int git_attr_file__load(
int
error
=
0
;
git_blob
*
blob
=
NULL
;
git_buf
content
=
GIT_BUF_INIT
;
const
char
*
data
=
NULL
;
git_attr_file
*
file
;
struct
stat
st
;
...
...
@@ -120,7 +119,9 @@ int git_attr_file__load(
(
error
=
git_blob_lookup
(
&
blob
,
repo
,
&
id
))
<
0
)
return
error
;
data
=
git_blob_rawcontent
(
blob
);
/* Do not assume that data straight from the ODB is NULL-terminated;
* copy the contents of a file to a buffer to work on */
git_buf_put
(
&
content
,
git_blob_rawcontent
(
blob
),
git_blob_rawsize
(
blob
));
break
;
}
case
GIT_ATTR_FILE__FROM_FILE
:
{
...
...
@@ -143,7 +144,6 @@ int git_attr_file__load(
if
(
error
<
0
)
return
GIT_ENOTFOUND
;
data
=
content
.
ptr
;
break
;
}
default:
...
...
@@ -154,7 +154,7 @@ int git_attr_file__load(
if
((
error
=
git_attr_file__new
(
&
file
,
entry
,
source
))
<
0
)
goto
cleanup
;
if
(
parser
&&
(
error
=
parser
(
repo
,
file
,
data
))
<
0
)
{
if
(
parser
&&
(
error
=
parser
(
repo
,
file
,
git_buf_cstr
(
&
content
)
))
<
0
)
{
git_attr_file__free
(
file
);
goto
cleanup
;
}
...
...
src/buf_text.c
View file @
e0482934
...
...
@@ -143,6 +143,7 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src)
tgt
->
ptr
[
tgt
->
size
++
]
=
'\n'
;
}
tgt
->
ptr
[
tgt
->
size
]
=
'\0'
;
return
git_buf_put
(
tgt
,
scan
,
end
-
scan
);
}
...
...
src/buffer.c
View file @
e0482934
...
...
@@ -176,10 +176,13 @@ int git_buf_putcn(git_buf *buf, char c, size_t len)
int
git_buf_put
(
git_buf
*
buf
,
const
char
*
data
,
size_t
len
)
{
ENSURE_SIZE
(
buf
,
buf
->
size
+
len
+
1
);
memmove
(
buf
->
ptr
+
buf
->
size
,
data
,
len
);
buf
->
size
+=
len
;
buf
->
ptr
[
buf
->
size
]
=
'\0'
;
if
(
len
)
{
assert
(
data
);
ENSURE_SIZE
(
buf
,
buf
->
size
+
len
+
1
);
memmove
(
buf
->
ptr
+
buf
->
size
,
data
,
len
);
buf
->
size
+=
len
;
buf
->
ptr
[
buf
->
size
]
=
'\0'
;
}
return
0
;
}
...
...
src/notes.c
View file @
e0482934
...
...
@@ -323,11 +323,10 @@ static int note_new(
git_signature_dup
(
&
note
->
committer
,
git_commit_committer
(
commit
))
<
0
)
return
-
1
;
note
->
message
=
git__str
dup
((
char
*
)
git_blob_rawcontent
(
blob
));
note
->
message
=
git__str
ndup
(
git_blob_rawcontent
(
blob
),
git_blob_rawsize
(
blob
));
GITERR_CHECK_ALLOC
(
note
->
message
);
*
out
=
note
;
return
0
;
}
...
...
tests/core/buffer.c
View file @
e0482934
...
...
@@ -281,11 +281,10 @@ check_buf_append_abc(
/* more variations on append tests */
void
test_core_buffer__5
(
void
)
{
check_buf_append
(
""
,
""
,
""
,
0
,
8
);
check_buf_append
(
"a"
,
""
,
"a"
,
1
,
8
);
check_buf_append
(
""
,
""
,
""
,
0
,
0
);
check_buf_append
(
"a"
,
""
,
"a"
,
1
,
0
);
check_buf_append
(
""
,
"a"
,
"a"
,
1
,
8
);
check_buf_append
(
""
,
"a"
,
"a"
,
1
,
8
);
check_buf_append
(
"a"
,
""
,
"a"
,
1
,
8
);
check_buf_append
(
"a"
,
"b"
,
"ab"
,
2
,
8
);
check_buf_append
(
""
,
"abcdefgh"
,
"abcdefgh"
,
8
,
16
);
check_buf_append
(
"abcdefgh"
,
""
,
"abcdefgh"
,
8
,
16
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment