Skip to content

Commit 9f932b9

Browse files
committed
mingw: avoid warnings when casting HANDLEs to int
HANDLE is defined internally as a void *, but in many cases it is actually guaranteed to be a 32-bit integer. In these cases, GCC should not warn about a cast of a pointer to an integer of a different type because we know exactly what we are doing. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7a6436e commit 9f932b9

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

compat/mingw.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "../run-command.h"
77
#include "../cache.h"
88

9+
#define HCAST(type, handle) ((type)(intptr_t)handle)
10+
911
static const int delay[] = { 0, 1, 10, 20, 40 };
1012

1113
int err_win_to_posix(DWORD winerr)
@@ -691,13 +693,13 @@ int pipe(int filedes[2])
691693
errno = err_win_to_posix(GetLastError());
692694
return -1;
693695
}
694-
filedes[0] = _open_osfhandle((int)h[0], O_NOINHERIT);
696+
filedes[0] = _open_osfhandle(HCAST(int, h[0]), O_NOINHERIT);
695697
if (filedes[0] < 0) {
696698
CloseHandle(h[0]);
697699
CloseHandle(h[1]);
698700
return -1;
699701
}
700-
filedes[1] = _open_osfhandle((int)h[1], O_NOINHERIT);
702+
filedes[1] = _open_osfhandle(HCAST(int, h[1]), O_NOINHERIT);
701703
if (filedes[1] < 0) {
702704
close(filedes[0]);
703705
CloseHandle(h[1]);
@@ -1846,7 +1848,8 @@ void mingw_open_html(const char *unixpath)
18461848
die("cannot run browser");
18471849

18481850
printf("Launching default browser to display HTML ...\n");
1849-
r = (int)ShellExecute(NULL, "open", htmlpath, NULL, "\\", SW_SHOWNORMAL);
1851+
r = HCAST(int, ShellExecute(NULL, "open", htmlpath,
1852+
NULL, "\\", SW_SHOWNORMAL));
18501853
FreeLibrary(shell32);
18511854
/* see the MSDN documentation referring to the result codes here */
18521855
if (r <= 32) {

compat/poll/poll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
#ifdef WIN32_NATIVE
7878

79-
#define IsConsoleHandle(h) (((long) (h) & 3) == 3)
79+
#define IsConsoleHandle(h) (((long) (intptr_t) (h) & 3) == 3)
8080

8181
static BOOL
8282
IsSocketHandle (HANDLE h)

compat/winansi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ static HANDLE duplicate_handle(HANDLE hnd)
454454
HANDLE hresult, hproc = GetCurrentProcess();
455455
if (!DuplicateHandle(hproc, hnd, hproc, &hresult, 0, TRUE,
456456
DUPLICATE_SAME_ACCESS))
457-
die_lasterr("DuplicateHandle(%li) failed", (long) hnd);
457+
die_lasterr("DuplicateHandle(%li) failed",
458+
(long) (intptr_t) hnd);
458459
return hresult;
459460
}
460461

0 commit comments

Comments
 (0)