refspec: make sure stack refspec_item variables are zeroed

A couple of functions that used struct refspec_item did not zero out the
structure memory. This can result in unexpected behavior, especially if
additional parameters are ever added to refspec_item in the future. Use
memset to ensure that unset structure members are zero.

It may make sense to convert most of these uses of struct refspec_item
to use either struct initializers or refspec_item_init_or_die. However,
other similar code uses memset. Converting all of these uses has been
left as a future exercise.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jacob Keller 2020-08-14 17:25:08 -07:00 коммит произвёл Junio C Hamano
Родитель 0becfec5b1
Коммит 95e7c38539
2 изменённых файлов: 2 добавлений и 0 удалений

Просмотреть файл

@ -478,6 +478,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat
struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;
struct refspec_item refspec;
memset(&refspec, 0, sizeof(refspec));
refspec.force = 0;
refspec.pattern = 1;
refspec.src = refspec.dst = "refs/heads/*";

Просмотреть файл

@ -443,6 +443,7 @@ void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int v
if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)
return;
memset(&rs, 0, sizeof(rs));
rs.src = ref->name;
rs.dst = NULL;