-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Assorted Coverity fixes #4702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assorted Coverity fixes #4702
Changes from all commits
ca9bbcb
17bd3b9
36a5b55
68c7480
6ae6491
8455a27
89091d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,7 +260,8 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf | |
git_strmap_insert(names, entry->value, git_buf_detach(&buf), &rval); | ||
if (rval < 0) { | ||
giterr_set(GITERR_NOMEMORY, "error inserting submodule into hash table"); | ||
return -1; | ||
error = -1; | ||
goto out; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually avoid freeing memory when we run in OOM situations. But as you cannot use |
||
} | ||
} | ||
if (error == GIT_ITEROVER) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -279,30 +279,34 @@ static int git_smart__connect( | |
return error; | ||
|
||
/* Detect capabilities */ | ||
if (git_smart__detect_caps(first, &t->caps, &symrefs) < 0) { | ||
free_symrefs(&symrefs); | ||
return -1; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually find this commit a bit hard to digest, as it simultaneously moves around code and changes it at the same time. I'd welcome it if you split it up into multiple commits to make it easier to understand what is going on here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, this seemed a simple fix, then memory-management happened. I'll try to split (the crux of the change is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hopefully the commits are more separated now, which clarifies what is happening. Note that I erroneously said Thinking back a bit more, I don't know if that's plausible protocol-wise, but at least coverity should be pleased… |
||
if ((error = git_smart__detect_caps(first, &t->caps, &symrefs)) == 0) { | ||
/* If the only ref in the list is capabilities^{} with OID_ZERO, remove it */ | ||
if (1 == t->refs.length && !strcmp(first->head.name, "capabilities^{}") && | ||
git_oid_iszero(&first->head.oid)) { | ||
git_vector_clear(&t->refs); | ||
git_pkt_free((git_pkt *)first); | ||
} | ||
|
||
/* If the only ref in the list is capabilities^{} with OID_ZERO, remove it */ | ||
if (1 == t->refs.length && !strcmp(first->head.name, "capabilities^{}") && | ||
git_oid_iszero(&first->head.oid)) { | ||
git_vector_clear(&t->refs); | ||
git_pkt_free((git_pkt *)first); | ||
/* Keep a list of heads for _ls */ | ||
git_smart__update_heads(t, &symrefs); | ||
} else if (error == GIT_ENOTFOUND) { | ||
/* There was no ref packet received, or the cap list was empty */ | ||
error = 0; | ||
} else { | ||
giterr_set(GITERR_NET, "invalid response"); | ||
goto cleanup; | ||
} | ||
|
||
/* Keep a list of heads for _ls */ | ||
git_smart__update_heads(t, &symrefs); | ||
|
||
free_symrefs(&symrefs); | ||
|
||
if (t->rpc && git_smart__reset_stream(t, false) < 0) | ||
return -1; | ||
if (t->rpc && (error = git_smart__reset_stream(t, false)) < 0) | ||
goto cleanup; | ||
|
||
/* We're now logically connected. */ | ||
t->connected = 1; | ||
|
||
return 0; | ||
cleanup: | ||
free_symrefs(&symrefs); | ||
|
||
return error; | ||
} | ||
|
||
static int git_smart__ls(const git_remote_head ***out, size_t *size, git_transport *transport) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,7 @@ int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vec | |
|
||
/* No refs or capabilites, odd but not a problem */ | ||
if (pkt == NULL || pkt->capabilities == NULL) | ||
return 0; | ||
return GIT_ENOTFOUND; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine, as there is only one caller of |
||
|
||
ptr = pkt->capabilities; | ||
while (ptr != NULL && *ptr != '\0') { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ignoring the error was actually intended. In case where we're unable to load the mail map, we simply ignore it and output commits with their original author/committer. You could add a comment and cast to
void
, thoughThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore the error even though I (the user) has asked for it ? I do not know if that's explicit, but I find this strange… How can I tell if the mailmap was applied when that happens ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, you're right. And in fact
git_mailmap_from_repository
also only errors out in case wheregit_mailmap_new
fails, but never if getting the actual mailmap fails. So checking the error is the right thing to do, and our future warning API should then handle errors when loading the mailmap itself (as described inmailmap_add_from_repository
)