summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-04-21 11:55:57 -0700
committerRussell Belfer <rb@github.com>2014-04-21 11:55:57 -0700
commit17ef678ca543d8b56035e36039ee319c12d0d249 (patch)
treeea7fa695cc304b9f4ee5f9b6f73a8b5a68c9e10a
parent28750a7d98ce5e23bac5c1d119109ded8e8aab73 (diff)
downloadlibgit2-17ef678ca543d8b56035e36039ee319c12d0d249.tar.gz
Fix some coverity-found issues
-rw-r--r--src/attr_file.c13
-rw-r--r--src/attrcache.c10
-rw-r--r--src/ignore.c6
-rw-r--r--src/index.c5
4 files changed, 16 insertions, 18 deletions
diff --git a/src/attr_file.c b/src/attr_file.c
index d107b5ab0..156a23d91 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -232,15 +232,14 @@ int git_attr_file__parse_buffer(
while (!error && *scan) {
/* allocate rule if needed */
- if (!rule) {
- if (!(rule = git__calloc(1, sizeof(*rule)))) {
- error = -1;
- break;
- }
- rule->match.flags = GIT_ATTR_FNMATCH_ALLOWNEG |
- GIT_ATTR_FNMATCH_ALLOWMACRO;
+ if (!rule && !(rule = git__calloc(1, sizeof(*rule)))) {
+ error = -1;
+ break;
}
+ rule->match.flags =
+ GIT_ATTR_FNMATCH_ALLOWNEG | GIT_ATTR_FNMATCH_ALLOWMACRO;
+
/* parse the next "pattern attr attr attr" line */
if (!(error = git_attr_fnmatch__parse(
&rule->match, &attrs->pool, context, &scan)) &&
diff --git a/src/attrcache.c b/src/attrcache.c
index a750154ce..f1bc70467 100644
--- a/src/attrcache.c
+++ b/src/attrcache.c
@@ -176,10 +176,9 @@ static int attr_cache_lookup(
goto cleanup;
entry = attr_cache_lookup_entry(cache, relfile);
- if (!entry) {
- if ((error = attr_cache_make_entry(&entry, repo, relfile)) < 0)
- goto cleanup;
- } else if (entry->file[source] != NULL) {
+ if (!entry)
+ error = attr_cache_make_entry(&entry, repo, relfile);
+ else if (entry->file[source] != NULL) {
file = entry->file[source];
GIT_REFCOUNT_INC(file);
}
@@ -254,8 +253,7 @@ bool git_attr_cache__is_cached(
khiter_t pos;
git_attr_file_entry *entry;
- if (!(cache = git_repository_attr_cache(repo)) ||
- !(files = cache->files))
+ if (!cache || !(files = cache->files))
return false;
pos = git_strmap_lookup_index(files, filename);
diff --git a/src/ignore.c b/src/ignore.c
index b08ff2200..f373c9482 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -32,9 +32,9 @@ static int parse_ignore_file(
}
while (!error && *scan) {
- if (!match) {
- match = git__calloc(1, sizeof(*match));
- GITERR_CHECK_ALLOC(match);
+ if (!match && !(match = git__calloc(1, sizeof(*match)))) {
+ error = -1;
+ break;
}
match->flags = GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG;
diff --git a/src/index.c b/src/index.c
index 083c01fe4..c044af402 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1880,8 +1880,9 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
git_oid checksum_calculated, checksum_expected;
#define seek_forward(_increase) { \
- if (_increase >= buffer_size) \
- return index_error_invalid("ran out of data while parsing"); \
+ if (_increase >= buffer_size) { \
+ error = index_error_invalid("ran out of data while parsing"); \
+ goto done; } \
buffer += _increase; \
buffer_size -= _increase;\
}