Skip to content

Commit 830ecd3

Browse files
committed
cat_one_file(): make it easy to see that the size variable is initialized
The large `switch` statement makes it a bit impractical to reason about the code. One of the code paths can technically lead to using `size` without being initialized: if the `t` case is taken and the type name is set to the empty string, we would actually leave `size` unintialized right until we use it. Practically, this cannot happen because the `do_oid_object_info_extended()` function is expected to always populate the `type_name` if asked for. However, it is quite unnecessary to leave the code as unwieldy to reason about: Just initialize the variable to 0 and be done with it. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 76d27a6 commit 830ecd3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

builtin/cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
106106
struct object_id oid;
107107
enum object_type type;
108108
char *buf;
109-
unsigned long size;
109+
unsigned long size = 0;
110110
struct object_context obj_context = {0};
111111
struct object_info oi = OBJECT_INFO_INIT;
112112
unsigned flags = OBJECT_INFO_LOOKUP_REPLACE;

0 commit comments

Comments
 (0)