{"thread":{"id":"66009","subject":"[PATCH] submodule--helper: avoid use of %zu for now","startedAt":"2026-07-15T20:10:09Z","lastAt":"2026-07-16T13:18:15Z","messageCount":3,"participants":["Junio C Hamano","Adrian Ratiu"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"548322","messageId":"xmqq4ii0ko9t.fsf@gitster.g","threadId":"66009","inReplyTo":null,"subject":"[PATCH] submodule--helper: avoid use of %zu for now","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-07-15T20:10:06Z","receivedAt":"2026-07-15T20:10:09Z","isPatch":true,"body":"Since d7d850e2b9 (CodingGuidelines: mention C99 features we can't\nuse, 2022-10-10), our CodingGuidelines document has explicitly\nforbidden the use of '%z' and '%zu' printf() format specifiers,\neven though C99 does support them.  However, a new instance crept\nin via 82c36fa0a9 (submodule: hash the submodule name for the\ngitdir path, 2026-01-12).\n\nWe could claim that this is an unintentional weather balloon that\nnobody has complained about for the past six months since Git 2.54,\nproving that it is now safe to use these format specifiers.  But\n(1) it is probably too early to make that claim, as distributions\noften stick to a stale version for several releases, and (2) it is\nunlikely that a failure in this code path would manifest as a\nmajor user-visible breakage that would trigger a failure report to\npercolate down to us.\n\nInstead, let's stick to the established workaround recommended by\nour CodingGuidelines, which is to cast the value to (uintmax_t) and\nformat it with PRIuMAX, at least for now.  Even if we eventually\nperform a bulk update using a Coccinelle script to transition to %z\nand %zu in the future, adding one more instance to the pile that\nwill need such a conversion is hardly a tragedy.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/submodule--helper.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git i/builtin/submodule--helper.c w/builtin/submodule--helper.c\nindex 1cc82a134d..92e38106c1 100644\n--- i/builtin/submodule--helper.c\n+++ w/builtin/submodule--helper.c\n@@ -549,7 +549,8 @@ static void create_default_gitdir_config(const char *submodule_name)\n \t}\n \n \t/* Case 2.4: If all the above failed, try a hash of the name as a last resort */\n-\theader_len = snprintf(header, sizeof(header), \"blob %zu\", strlen(submodule_name));\n+\theader_len = snprintf(header, sizeof(header),\n+\t\t\t      \"blob %\"PRIuMAX, (uintmax_t)strlen(submodule_name));\n \tthe_hash_algo->init_fn(&ctx);\n \tthe_hash_algo->update_fn(&ctx, header, header_len);\n \tthe_hash_algo->update_fn(&ctx, \"\\0\", 1);\n"},{"id":"548402","messageId":"87a4rrxg3r.fsf@gentoo.mail-host-address-is-not-set","threadId":"66009","inReplyTo":"xmqq4ii0ko9t.fsf@gitster.g","subject":"Re: [PATCH] submodule--helper: avoid use of %zu for now","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-07-16T12:40:24Z","receivedAt":"2026-07-16T12:40:34Z","isPatch":true,"body":"On Wed, 15 Jul 2026, Junio C Hamano <gitster@pobox.com> wrote:\n> Since d7d850e2b9 (CodingGuidelines: mention C99 features we can't\n> use, 2022-10-10), our CodingGuidelines document has explicitly\n> forbidden the use of '%z' and '%zu' printf() format specifiers,\n> even though C99 does support them.  However, a new instance crept\n> in via 82c36fa0a9 (submodule: hash the submodule name for the\n> gitdir path, 2026-01-12).\n>\n> We could claim that this is an unintentional weather balloon that\n> nobody has complained about for the past six months since Git 2.54,\n> proving that it is now safe to use these format specifiers.  But\n> (1) it is probably too early to make that claim, as distributions\n> often stick to a stale version for several releases, and (2) it is\n> unlikely that a failure in this code path would manifest as a\n> major user-visible breakage that would trigger a failure report to\n> percolate down to us.\n>\n> Instead, let's stick to the established workaround recommended by\n> our CodingGuidelines, which is to cast the value to (uintmax_t) and\n> format it with PRIuMAX, at least for now.  Even if we eventually\n> perform a bulk update using a Coccinelle script to transition to %z\n> and %zu in the future, adding one more instance to the pile that\n> will need such a conversion is hardly a tragedy.\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>  builtin/submodule--helper.c | 3 ++-\n>  1 file changed, 2 insertions(+), 1 deletion(-)\n>\n> diff --git i/builtin/submodule--helper.c w/builtin/submodule--helper.c\n> index 1cc82a134d..92e38106c1 100644\n> --- i/builtin/submodule--helper.c\n> +++ w/builtin/submodule--helper.c\n> @@ -549,7 +549,8 @@ static void create_default_gitdir_config(const char *submodule_name)\n>  \t}\n>  \n>  \t/* Case 2.4: If all the above failed, try a hash of the name as a last resort */\n> -\theader_len = snprintf(header, sizeof(header), \"blob %zu\", strlen(submodule_name));\n> +\theader_len = snprintf(header, sizeof(header),\n> +\t\t\t      \"blob %\"PRIuMAX, (uintmax_t)strlen(submodule_name));\n>  \tthe_hash_algo->init_fn(&ctx);\n>  \tthe_hash_algo->update_fn(&ctx, header, header_len);\n>  \tthe_hash_algo->update_fn(&ctx, \"\\0\", 1);\n\n\nLGTM and sorry for not following the guideline. :)\n"},{"id":"548403","messageId":"xmqqa4rrjcob.fsf@gitster.g","threadId":"66009","inReplyTo":"87a4rrxg3r.fsf@gentoo.mail-host-address-is-not-set","subject":"Re: [PATCH] submodule--helper: avoid use of %zu for now","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-07-16T13:18:12Z","receivedAt":"2026-07-16T13:18:15Z","isPatch":true,"body":"Adrian Ratiu <adrian.ratiu@collabora.com> writes:\n\n>\n>\n> LGTM and sorry for not following the guideline. :)\n\nThanks, and no worries.  We all make mistakes.\n"}]}