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
00258cc0
Commit
00258cc0
authored
Mar 06, 2014
by
Jiri Pospisil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
git_oid_fromstrn: Simplify the implementation and fix memory access issues
parent
c81e4adf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
15 deletions
+9
-15
src/oid.c
+9
-15
No files found.
src/oid.c
View file @
00258cc0
...
...
@@ -24,30 +24,24 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
size_t
p
;
int
v
;
if
(
length
>
GIT_OID_HEXSZ
)
return
oid_error_invalid
(
"too long"
);
assert
(
out
&&
str
);
for
(
p
=
0
;
p
<
length
-
1
;
p
+=
2
)
{
v
=
(
git__fromhex
(
str
[
p
+
0
])
<<
4
)
|
git__fromhex
(
str
[
p
+
1
]);
if
(
!
length
)
return
oid_error_invalid
(
"too short"
);
if
(
v
<
0
)
return
oid_error_invalid
(
"contains invalid characters
"
);
if
(
length
>
GIT_OID_HEXSZ
)
return
oid_error_invalid
(
"too long
"
);
out
->
id
[
p
/
2
]
=
(
unsigned
char
)
v
;
}
memset
(
out
->
id
,
0
,
GIT_OID_RAWSZ
);
if
(
length
%
2
)
{
v
=
(
git__fromhex
(
str
[
p
+
0
])
<<
4
);
for
(
p
=
0
;
p
<
length
;
p
++
)
{
v
=
git__fromhex
(
str
[
p
]
);
if
(
v
<
0
)
return
oid_error_invalid
(
"contains invalid characters"
);
out
->
id
[
p
/
2
]
=
(
unsigned
char
)
v
;
p
+=
2
;
out
->
id
[
p
/
2
]
|=
(
unsigned
char
)(
v
<<
(
p
%
2
?
0
:
4
));
}
memset
(
out
->
id
+
p
/
2
,
0
,
(
GIT_OID_HEXSZ
-
p
)
/
2
);
return
0
;
}
...
...
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