Skip to content

Commit 1cb2f29

Browse files
peffgitster
authored andcommitted
unpack_loose_rest(): rewrite return handling for clarity
We have a pattern like: if (error1) ...handle error 1... else if (error2) ...handle error 2... else ...return buf... ...free buf and return NULL... This is a little subtle because it is the return in the success block that lets us skip the common error handling. Rewrite this instead to free the buffer in each error path, marking it as NULL, and then all code paths can use the common return. This should make the logic a bit easier to follow. It does mean duplicating the buf cleanup for errors, but it's a single line. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 547f719 commit 1cb2f29

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

object-file.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,16 +1348,16 @@ static void *unpack_loose_rest(git_zstream *stream,
13481348
}
13491349
}
13501350

1351-
if (status != Z_STREAM_END)
1351+
if (status != Z_STREAM_END) {
13521352
error(_("corrupt loose object '%s'"), oid_to_hex(oid));
1353-
else if (stream->avail_in)
1353+
FREE_AND_NULL(buf);
1354+
} else if (stream->avail_in) {
13541355
error(_("garbage at end of loose object '%s'"),
13551356
oid_to_hex(oid));
1356-
else
1357-
return buf;
1357+
FREE_AND_NULL(buf);
1358+
}
13581359

1359-
free(buf);
1360-
return NULL;
1360+
return buf;
13611361
}
13621362

13631363
/*

0 commit comments

Comments
 (0)