Skip to content

Commit 7c07385

Browse files
peffgitster
authored andcommitted
zero-initialize object_info structs
The sha1_object_info_extended function expects the caller to provide a "struct object_info" which contains pointers to "query" items that will be filled in. The purpose of providing pointers rather than storing the response directly in the struct is so that callers can choose not to incur the expense in finding particular fields that they do not care about. Right now the only query item is "sizep", and all callers set it explicitly to choose whether or not to query it; they can then leave the rest of the struct uninitialized. However, as we add new query items, each caller will have to be updated to explicitly turn off the new ones (by setting them to NULL). Instead, let's teach each caller to zero-initialize the struct, so that they do not have to learn about each new query item added. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent edca415 commit 7c07385

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

sha1_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2409,7 +2409,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
24092409

24102410
int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
24112411
{
2412-
struct object_info oi;
2412+
struct object_info oi = {0};
24132413

24142414
oi.sizep = sizep;
24152415
return sha1_object_info_extended(sha1, &oi);

streaming.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ struct git_istream *open_istream(const unsigned char *sha1,
135135
struct stream_filter *filter)
136136
{
137137
struct git_istream *st;
138-
struct object_info oi;
138+
struct object_info oi = {0};
139139
const unsigned char *real = lookup_replace_object(sha1);
140140
enum input_source src = istream_source(real, type, &oi);
141141

0 commit comments

Comments
 (0)