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
c94bc192
Commit
c94bc192
authored
Aug 17, 2011
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #375 from schu/cleanup
cleanup: some nitpicking and missing free's.
parents
ec5b1589
d4958b88
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
19 deletions
+41
-19
src/config_file.c
+14
-5
src/reflog.c
+21
-8
src/refs.c
+0
-2
src/tsort.c
+2
-1
src/unix/posix.h
+0
-1
src/util.h
+4
-2
No files found.
src/config_file.c
View file @
c94bc192
...
@@ -212,8 +212,10 @@ static int cvar_normalize_name(cvar_t *var, char **output)
...
@@ -212,8 +212,10 @@ static int cvar_normalize_name(cvar_t *var, char **output)
/* If there aren't any spaces in the section, it's easy */
/* If there aren't any spaces in the section, it's easy */
if
(
section_sp
==
NULL
)
{
if
(
section_sp
==
NULL
)
{
ret
=
snprintf
(
name
,
len
+
1
,
"%s.%s"
,
var
->
section
,
var
->
name
);
ret
=
snprintf
(
name
,
len
+
1
,
"%s.%s"
,
var
->
section
,
var
->
name
);
if
(
ret
<
0
)
if
(
ret
<
0
)
{
free
(
name
);
return
git__throw
(
GIT_EOSERR
,
"Failed to normalize name. OS err: %s"
,
strerror
(
errno
));
return
git__throw
(
GIT_EOSERR
,
"Failed to normalize name. OS err: %s"
,
strerror
(
errno
));
}
*
output
=
name
;
*
output
=
name
;
return
GIT_SUCCESS
;
return
GIT_SUCCESS
;
...
@@ -701,12 +703,16 @@ static int parse_section_header(diskfile_backend *cfg, char **section_out)
...
@@ -701,12 +703,16 @@ static int parse_section_header(diskfile_backend *cfg, char **section_out)
/* find the end of the variable's name */
/* find the end of the variable's name */
name_end
=
strchr
(
line
,
']'
);
name_end
=
strchr
(
line
,
']'
);
if
(
name_end
==
NULL
)
if
(
name_end
==
NULL
)
{
free
(
line
);
return
git__throw
(
GIT_EOBJCORRUPTED
,
"Failed to parse header. Can't find header name end"
);
return
git__throw
(
GIT_EOBJCORRUPTED
,
"Failed to parse header. Can't find header name end"
);
}
name
=
(
char
*
)
git__malloc
((
size_t
)(
name_end
-
line
)
+
1
);
name
=
(
char
*
)
git__malloc
((
size_t
)(
name_end
-
line
)
+
1
);
if
(
name
==
NULL
)
if
(
name
==
NULL
)
{
free
(
line
);
return
GIT_ENOMEM
;
return
GIT_ENOMEM
;
}
name_length
=
0
;
name_length
=
0
;
pos
=
0
;
pos
=
0
;
...
@@ -738,8 +744,10 @@ static int parse_section_header(diskfile_backend *cfg, char **section_out)
...
@@ -738,8 +744,10 @@ static int parse_section_header(diskfile_backend *cfg, char **section_out)
}
while
((
c
=
line
[
pos
++
])
!=
']'
);
}
while
((
c
=
line
[
pos
++
])
!=
']'
);
if
(
line
[
pos
-
1
]
!=
']'
)
if
(
line
[
pos
-
1
]
!=
']'
)
{
return
git__throw
(
GIT_EOBJCORRUPTED
,
"Failed to parse header. Config file ended unexpectedly"
);
error
=
git__throw
(
GIT_EOBJCORRUPTED
,
"Failed to parse header. Config file ended unexpectedly"
);
goto
error
;
}
name
[
name_length
]
=
0
;
name
[
name_length
]
=
0
;
free
(
line
);
free
(
line
);
...
@@ -957,6 +965,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
...
@@ -957,6 +965,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
* default case will take care of updating them.
* default case will take care of updating them.
*/
*/
pre_end
=
post_start
=
cfg
->
reader
.
read_ptr
;
pre_end
=
post_start
=
cfg
->
reader
.
read_ptr
;
if
(
current_section
)
free
(
current_section
);
free
(
current_section
);
error
=
parse_section_header
(
cfg
,
&
current_section
);
error
=
parse_section_header
(
cfg
,
&
current_section
);
if
(
error
<
GIT_SUCCESS
)
if
(
error
<
GIT_SUCCESS
)
...
...
src/reflog.c
View file @
c94bc192
...
@@ -102,8 +102,12 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
...
@@ -102,8 +102,12 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
git_reflog_entry
*
entry
;
git_reflog_entry
*
entry
;
#define seek_forward(_increase) { \
#define seek_forward(_increase) { \
if (_increase >= buf_size) \
if (_increase >= buf_size) { \
if (entry->committer) \
free(entry->committer); \
free(entry); \
return git__throw(GIT_ERROR, "Failed to seek forward. Buffer size exceeded"); \
return git__throw(GIT_ERROR, "Failed to seek forward. Buffer size exceeded"); \
} \
buf += _increase; \
buf += _increase; \
buf_size -= _increase; \
buf_size -= _increase; \
}
}
...
@@ -112,13 +116,18 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
...
@@ -112,13 +116,18 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
entry
=
git__malloc
(
sizeof
(
git_reflog_entry
));
entry
=
git__malloc
(
sizeof
(
git_reflog_entry
));
if
(
entry
==
NULL
)
if
(
entry
==
NULL
)
return
GIT_ENOMEM
;
return
GIT_ENOMEM
;
entry
->
committer
=
NULL
;
if
(
git_oid_fromstrn
(
&
entry
->
oid_old
,
buf
,
GIT_OID_HEXSZ
)
<
GIT_SUCCESS
)
if
(
git_oid_fromstrn
(
&
entry
->
oid_old
,
buf
,
GIT_OID_HEXSZ
)
<
GIT_SUCCESS
)
{
free
(
entry
);
return
GIT_ERROR
;
return
GIT_ERROR
;
}
seek_forward
(
GIT_OID_HEXSZ
+
1
);
seek_forward
(
GIT_OID_HEXSZ
+
1
);
if
(
git_oid_fromstrn
(
&
entry
->
oid_cur
,
buf
,
GIT_OID_HEXSZ
)
<
GIT_SUCCESS
)
if
(
git_oid_fromstrn
(
&
entry
->
oid_cur
,
buf
,
GIT_OID_HEXSZ
)
<
GIT_SUCCESS
)
{
free
(
entry
);
return
GIT_ERROR
;
return
GIT_ERROR
;
}
seek_forward
(
GIT_OID_HEXSZ
+
1
);
seek_forward
(
GIT_OID_HEXSZ
+
1
);
ptr
=
buf
;
ptr
=
buf
;
...
@@ -128,11 +137,16 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
...
@@ -128,11 +137,16 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
seek_forward
(
1
);
seek_forward
(
1
);
entry
->
committer
=
git__malloc
(
sizeof
(
git_signature
));
entry
->
committer
=
git__malloc
(
sizeof
(
git_signature
));
if
(
entry
->
committer
==
NULL
)
if
(
entry
->
committer
==
NULL
)
{
free
(
entry
);
return
GIT_ENOMEM
;
return
GIT_ENOMEM
;
}
if
((
error
=
git_signature__parse
(
entry
->
committer
,
&
ptr
,
buf
+
1
,
NULL
,
*
buf
))
<
GIT_SUCCESS
)
if
((
error
=
git_signature__parse
(
entry
->
committer
,
&
ptr
,
buf
+
1
,
NULL
,
*
buf
))
<
GIT_SUCCESS
)
{
goto
cleanup
;
free
(
entry
->
committer
);
free
(
entry
);
return
git__rethrow
(
error
,
"Failed to parse reflog. Could not parse signature"
);
}
if
(
*
buf
==
'\t'
)
{
if
(
*
buf
==
'\t'
)
{
/* We got a message. Read everything till we reach LF. */
/* We got a message. Read everything till we reach LF. */
...
@@ -150,12 +164,11 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
...
@@ -150,12 +164,11 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
seek_forward
(
1
);
seek_forward
(
1
);
if
((
error
=
git_vector_insert
(
&
log
->
entries
,
entry
))
<
GIT_SUCCESS
)
if
((
error
=
git_vector_insert
(
&
log
->
entries
,
entry
))
<
GIT_SUCCESS
)
goto
cleanup
;
return
git__rethrow
(
error
,
"Failed to parse reflog. Could not add new entry"
)
;
}
}
#undef seek_forward
#undef seek_forward
cleanup:
return
error
==
GIT_SUCCESS
?
GIT_SUCCESS
:
git__rethrow
(
error
,
"Failed to parse reflog"
);
return
error
==
GIT_SUCCESS
?
GIT_SUCCESS
:
git__rethrow
(
error
,
"Failed to parse reflog"
);
}
}
...
...
src/refs.c
View file @
c94bc192
...
@@ -1659,8 +1659,6 @@ static int check_valid_ref_char(char ch)
...
@@ -1659,8 +1659,6 @@ static int check_valid_ref_char(char ch)
case
'['
:
case
'['
:
case
'*'
:
case
'*'
:
return
GIT_ERROR
;
return
GIT_ERROR
;
break
;
default:
default:
return
GIT_SUCCESS
;
return
GIT_SUCCESS
;
}
}
...
...
src/tsort.c
View file @
c94bc192
#include <common.h>
#include "common.h"
/**
/**
* An array-of-pointers implementation of Python's Timsort
* An array-of-pointers implementation of Python's Timsort
...
...
src/unix/posix.h
View file @
c94bc192
#ifndef INCLUDE_posix__w32_h__
#ifndef INCLUDE_posix__w32_h__
#define INCLUDE_posix__w32_h__
#define INCLUDE_posix__w32_h__
#include "common.h"
#include <fnmatch.h>
#include <fnmatch.h>
#define p_lstat(p,b) lstat(p,b)
#define p_lstat(p,b) lstat(p,b)
...
...
src/util.h
View file @
c94bc192
...
@@ -47,11 +47,13 @@ GIT_INLINE(char *) git__strndup(const char *str, size_t n)
...
@@ -47,11 +47,13 @@ GIT_INLINE(char *) git__strndup(const char *str, size_t n)
length
=
n
;
length
=
n
;
ptr
=
(
char
*
)
malloc
(
length
+
1
);
ptr
=
(
char
*
)
malloc
(
length
+
1
);
if
(
!
ptr
)
if
(
!
ptr
)
{
git__throw
(
GIT_ENOMEM
,
"Out of memory. Failed to duplicate string"
);
git__throw
(
GIT_ENOMEM
,
"Out of memory. Failed to duplicate string"
);
return
NULL
;
}
memcpy
(
ptr
,
str
,
length
);
memcpy
(
ptr
,
str
,
length
);
ptr
[
length
]
=
0
;
ptr
[
length
]
=
'\0'
;
return
ptr
;
return
ptr
;
}
}
...
...
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