Skip to content

Commit 709fdce

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6e1d0ce commit 709fdce

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

compat/win32/headless.c

+9-8
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ int WINAPI wWinMain(_In_ HINSTANCE instance,
5353
wchar_t git_command_line[32768];
5454
size_t size = sizeof(git_command_line) / sizeof(wchar_t);
5555
const wchar_t *needs_quotes = L"";
56-
int slash = 0, i;
56+
size_t slash = 0;
57+
int len;
5758

5859
STARTUPINFO startup_info = {
5960
.cb = sizeof(STARTUPINFO),
@@ -66,7 +67,7 @@ int WINAPI wWinMain(_In_ HINSTANCE instance,
6667
DWORD exit_code;
6768

6869
/* First, determine the full path of argv[0] */
69-
for (i = 0; _wpgmptr[i]; i++)
70+
for (size_t i = 0; _wpgmptr[i]; i++)
7071
if (_wpgmptr[i] == L' ')
7172
needs_quotes = L"\"";
7273
else if (_wpgmptr[i] == L'\\')
@@ -79,16 +80,16 @@ int WINAPI wWinMain(_In_ HINSTANCE instance,
7980
extend_path(_wpgmptr, slash);
8081

8182
/* 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)
8586
return 127; /* Too long path */
8687

8788
if (*command_line) {
8889
/* 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)
9293
return 127;
9394
}
9495

0 commit comments

Comments
 (0)