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
2a0d0bd1
Unverified
Commit
2a0d0bd1
authored
Mar 02, 2022
by
Edward Thomson
Committed by
GitHub
Mar 02, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6238 from libgit2/ethomson/coverity
Some minor fixes for issues discovered by coverity
parents
da0b0354
073e63d0
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
7 deletions
+49
-7
src/cli/opt_usage.c
+1
-1
src/libgit2/object.c
+1
-0
src/libgit2/refdb_fs.c
+5
-1
src/libgit2/transports/httpclient.c
+1
-1
src/util/assert_safe.h
+16
-0
src/util/fs_path.c
+2
-4
tests/util/assert.c
+23
-0
No files found.
src/cli/opt_usage.c
View file @
2a0d0bd1
...
...
@@ -150,7 +150,7 @@ int cli_opt_help_fprint(
{
git_str
help
=
GIT_BUF_INIT
;
const
cli_opt_spec
*
spec
;
int
error
;
int
error
=
0
;
/* Display required arguments first */
for
(
spec
=
specs
;
spec
->
type
;
++
spec
)
{
...
...
src/libgit2/object.c
View file @
2a0d0bd1
...
...
@@ -250,6 +250,7 @@ int git_object_lookup_prefix(
if
(
error
<
0
)
return
error
;
GIT_ASSERT
(
odb_obj
);
error
=
git_object__from_odb_object
(
object_out
,
repo
,
odb_obj
,
type
);
git_odb_object_free
(
odb_obj
);
...
...
src/libgit2/refdb_fs.c
View file @
2a0d0bd1
...
...
@@ -1361,7 +1361,11 @@ static int packed_write(refdb_fs_backend *backend)
for
(
i
=
0
;
i
<
git_sortedcache_entrycount
(
refcache
);
++
i
)
{
struct
packref
*
ref
=
git_sortedcache_entry
(
refcache
,
i
);
GIT_ASSERT
(
ref
);
GIT_ASSERT_WITH_CLEANUP
(
ref
,
{
error
=
-
1
;
goto
fail
;
});
if
((
error
=
packed_find_peel
(
backend
,
ref
))
<
0
)
goto
fail
;
...
...
src/libgit2/transports/httpclient.c
View file @
2a0d0bd1
...
...
@@ -395,7 +395,7 @@ static int on_body(http_parser *parser, const char *buf, size_t len)
size_t
max_len
;
/* Saw data when we expected not to (eg, in consume_response_body) */
if
(
ctx
->
output_buf
==
NULL
&&
ctx
->
output_size
==
0
)
{
if
(
ctx
->
output_buf
==
NULL
||
ctx
->
output_size
==
0
)
{
ctx
->
parse_status
=
PARSE_STATUS_NO_OUTPUT
;
return
0
;
}
...
...
src/util/assert_safe.h
View file @
2a0d0bd1
...
...
@@ -24,6 +24,8 @@
# define GIT_ASSERT_WITH_RETVAL(expr, fail) assert(expr)
# define GIT_ASSERT_ARG_WITH_RETVAL(expr, fail) assert(expr)
# define GIT_ASSERT_WITH_CLEANUP(expr, cleanup) assert(expr)
#else
/** Internal consistency check to stop the function. */
...
...
@@ -53,6 +55,20 @@
} \
} while(0)
/**
* Go to to the given label on assertion failures; useful when you have
* taken a lock or otherwise need to release a resource.
*/
# define GIT_ASSERT_WITH_CLEANUP(expr, cleanup) \
GIT_ASSERT__WITH_CLEANUP(expr, GIT_ERROR_INTERNAL, "unrecoverable internal error", cleanup)
# define GIT_ASSERT__WITH_CLEANUP(expr, code, msg, cleanup) do { \
if (!(expr)) { \
git_error_set(code, "%s: '%s'", msg, #expr); \
cleanup; \
} \
} while(0)
#endif
/* GIT_ASSERT_HARD */
#endif
src/util/fs_path.c
View file @
2a0d0bd1
...
...
@@ -193,8 +193,7 @@ int git_fs_path_dirname_r(git_str *buffer, const char *path)
if
(
endp
-
path
+
1
>
INT_MAX
)
{
git_error_set
(
GIT_ERROR_INVALID
,
"path too long"
);
len
=
-
1
;
goto
Exit
;
return
-
1
;
}
if
((
len
=
win32_prefix_length
(
path
,
(
int
)(
endp
-
path
+
1
)))
>
0
)
{
...
...
@@ -219,8 +218,7 @@ int git_fs_path_dirname_r(git_str *buffer, const char *path)
if
(
endp
-
path
+
1
>
INT_MAX
)
{
git_error_set
(
GIT_ERROR_INVALID
,
"path too long"
);
len
=
-
1
;
goto
Exit
;
return
-
1
;
}
if
((
len
=
win32_prefix_length
(
path
,
(
int
)(
endp
-
path
+
1
)))
>
0
)
{
...
...
tests/util/assert.c
View file @
2a0d0bd1
...
...
@@ -36,6 +36,21 @@ static const char *bad_returns_string(void)
return
hello_world
;
}
static
int
has_cleanup
(
void
)
{
int
error
=
42
;
GIT_ASSERT_WITH_CLEANUP
(
1
+
1
==
3
,
{
error
=
99
;
goto
foobar
;
});
return
0
;
foobar:
return
error
;
}
void
test_assert__argument
(
void
)
{
cl_git_fail
(
dummy_fn
(
NULL
));
...
...
@@ -92,3 +107,11 @@ void test_assert__internal(void)
cl_assert_equal_i
(
GIT_ERROR_INTERNAL
,
git_error_last
()
->
klass
);
cl_assert_equal_s
(
"unrecoverable internal error: '1 + 1 == 3'"
,
git_error_last
()
->
message
);
}
void
test_assert__with_cleanup
(
void
)
{
cl_git_fail_with
(
99
,
has_cleanup
());
cl_assert
(
git_error_last
());
cl_assert_equal_i
(
GIT_ERROR_INTERNAL
,
git_error_last
()
->
klass
);
cl_assert_equal_s
(
"unrecoverable internal error: '1 + 1 == 3'"
,
git_error_last
()
->
message
);
}
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