Re: [PATCH v1 1/4] fsck: introduce "FSCK_REF_REPORT_DEFAULT" macro
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 20, 2024, 16:25 UTC
- Message-ID
- <xmqq4j7fb1pn.fsf@gitster.g>
- In-Reply-To
- <ZsIM0L72bei9Fudt@ArchLinux>
shejialuo <shejialuo@gmail.com> writes:
> In "fsck.c::fsck_refs_error_function", we need to tell whether "oid" and > "referent" is NULL. So, we need to always initialize these parameters to > NULL instead of letting them point to anywhere when creating a new > "fsck_ref_report" structure.
The above is correct, but ...
> if (check_refname_format(iter->basename, REFNAME_ALLOW_ONELEVEL)) {
> - struct fsck_ref_report report = { .path = NULL };
> + struct fsck_ref_report report = FSCK_REF_REPORT_DEFAULT;... the code without this patch is already doing so.
When designated initializers are used to initialize a struct, all members that are not initialized explicitly are implicitly initialized the same as for objects that have static storage duration (meaning: pointers are initialized to NULL, arithmetics are initialized to zero).
So I do not quite see why this change is needed. By hiding the fact that the "report" structure is zero-initialized behind the macro, it makes it less obvious that we are clearing everything.
If the patch were to rewrite the above like so:
struct fsck_ref_report report = { 0 }it would make it even more clear that everything is zero initialized, and also makes it obvious that .path member is not any special.
Thanks.