Skip to content

Commit 01d1c23

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]>
1 parent 33d93d6 commit 01d1c23

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
unsigned int _CRT_fmode = _O_BINARY;
1113

@@ -726,13 +728,13 @@ int pipe(int filedes[2])
726728
errno = err_win_to_posix(GetLastError());
727729
return -1;
728730
}
729-
filedes[0] = _open_osfhandle((int)h[0], O_NOINHERIT);
731+
filedes[0] = _open_osfhandle(HCAST(int, h[0]), O_NOINHERIT);
730732
if (filedes[0] < 0) {
731733
CloseHandle(h[0]);
732734
CloseHandle(h[1]);
733735
return -1;
734736
}
735-
filedes[1] = _open_osfhandle((int)h[1], O_NOINHERIT);
737+
filedes[1] = _open_osfhandle(HCAST(int, h[1]), O_NOINHERIT);
736738
if (filedes[0] < 0) {
737739
close(filedes[0]);
738740
CloseHandle(h[1]);
@@ -1949,7 +1951,8 @@ void mingw_open_html(const char *unixpath)
19491951
die("cannot run browser");
19501952

19511953
printf("Launching default browser to display HTML ...\n");
1952-
r = (int)ShellExecute(NULL, "open", htmlpath, NULL, "\\", SW_SHOWNORMAL);
1954+
r = HCAST(int, ShellExecute(NULL, "open", htmlpath,
1955+
NULL, "\\", SW_SHOWNORMAL));
19531956
FreeLibrary(shell32);
19541957
/* see the MSDN documentation referring to the result codes here */
19551958
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)