In line 1763 of unpack-tree.c we have a condition on the current tree
        if (current) {
Within this block of code we can assume current to be non NULL, hence
the code after the statement in line 1796:
        if (current)
                return ...

cannot be reached.

The proposed patch here changes the order of the current tree and the
newtree part. I'm not sure if that's the right way to handle it.

All referenced lines have been introduced in the same commit
076b0adc (2006-07-30, read-tree: move merge functions to the library),
which was just moving the code around.
The outer condition on the current tree (now in line 1763) was introduced
in c859600954df4c292e, June 2005, [PATCH] read-tree: save more user hassles 
during fast-forward.
The inner condition on the current tree was introduced in
ee6566e8d70da682ac4926d, Sept. 2005, [PATCH] Rewrite read-tree

This issue was found by coverity, Id:290002

Signed-off-by: Stefan Beller <>
 unpack-trees.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/unpack-trees.c b/unpack-trees.c
index c6aa8fb..e6d37ff 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1793,11 +1793,10 @@ int twoway_merge(const struct cache_entry * const *src,
                        /* all other failures */
                        if (oldtree)
                                return o->gently ? -1 : reject_merge(oldtree, 
-                       if (current)
-                               return o->gently ? -1 : reject_merge(current, 
                        if (newtree)
                                return o->gently ? -1 : reject_merge(newtree, 
-                       return -1;
+                       /* current is definitely exists here */
+                       return o->gently ? -1 : reject_merge(current, o);
        else if (newtree) {

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to