compat/win32: fix -Wsign-compare warning in "wWinMain()"

GCC generates a warning in "headless.c" because we compare `slash` with `size`, where the former is an `int` and the latter is a `size_t`. Fix the warning by storing `slash` as a `size_t`, as well. This commit is being singled out because the file does not include the "git-compat-util.h" header, and consequently, we cannot easily mark it with the `DISABLE_SIGN_COMPARE_WARNING` macro. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Dec 6, 2024 at 11:27 UTC 709fdce0893f93464435841e0eb9f6df3fd73807
1 file changed +9 -8
compat/win32/headless.c
+9 -8
@@ -53,7 +53,8 @@ int WINAPI wWinMain(_In_ HINSTANCE instance,
53 wchar_t git_command_line[32768];
54 size_t size = sizeof(git_command_line) / sizeof(wchar_t);
55 const wchar_t *needs_quotes = L"";
56 - int slash = 0, i;
56 + size_t slash = 0;
57 + int len;
58
59 STARTUPINFO startup_info = {
60 .cb = sizeof(STARTUPINFO),
@@ -66,7 +67,7 @@ int WINAPI wWinMain(_In_ HINSTANCE instance,
67 DWORD exit_code;
68
69 /* First, determine the full path of argv[0] */
69 - for (i = 0; _wpgmptr[i]; i++)
70 + for (size_t i = 0; _wpgmptr[i]; i++)
71 if (_wpgmptr[i] == L' ')
72 needs_quotes = L"\"";
73 else if (_wpgmptr[i] == L'\\')
@@ -79,16 +80,16 @@ int WINAPI wWinMain(_In_ HINSTANCE instance,
80 extend_path(_wpgmptr, slash);
81
82 /* Then, add the full path of `git.exe` as argv[0] */
82 - i = swprintf_s(git_command_line, size, L"%ls%.*ls\\git.exe%ls",
83 - needs_quotes, slash, _wpgmptr, needs_quotes);
84 - if (i < 0)
83 + len = swprintf_s(git_command_line, size, L"%ls%.*ls\\git.exe%ls",
84 + needs_quotes, (int) slash, _wpgmptr, needs_quotes);
85 + if (len < 0)
86 return 127; /* Too long path */
87
88 if (*command_line) {
89 /* Now, append the command-line arguments */
89 - i = swprintf_s(git_command_line + i, size - i,
90 - L" %ls", command_line);
91 - if (i < 0)
90 + len = swprintf_s(git_command_line + len, size - len,
91 + L" %ls", command_line);
92 + if (len < 0)
93 return 127;
94 }
95