git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 12/14] Fix pointer -> integer casts on IL32P64 systems

From
Marat Radchenko <marat@slonopotamus.org>
Date
Sep 30, 2014, 07:02 UTC
Message-ID
<1412060563-22041-13-git-send-email-marat@slonopotamus.org>
In-Reply-To
<1412060563-22041-1-git-send-email-marat@slonopotamus.org>

This commit touches regcomp.c and poll.c from Gnulib, both were fixed upstream in 2012 the same way.

Also, this commit touches regex_internal.h from Gnulib, which was fixed upstream in 2005.

Wrt ShellExecute in winansi.c, quoting [1]:
  MSDN says you can cast the result to an integer and compare the result
  against 32... You could cast in the other direction, comparing the return
  value against (HINSTANCE)32... Or you could cast the result to an INT_PTR
  and compare the result against 32.
We use the third option: cast HINSTANCE to intptr_t.
[1]: http://blogs.msdn.com/b/oldnewthing/archive/2006/11/08/1035971.aspx
Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
---
 compat/mingw.c                | 8 ++++----
 compat/poll/poll.c            | 2 +-
 compat/regex/regcomp.c        | 4 ++--
 compat/regex/regex_internal.h | 1 +
 compat/win32/pthread.h        | 2 +-
 compat/winansi.c              | 2 +-
 pack-revindex.c               | 2 +-
 sha1_file.c                   | 8 ++++----
 8 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index c5c37e5..27925d9 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -674,13 +674,13 @@ int pipe(int filedes[2])
 		errno = err_win_to_posix(GetLastError());
 		return -1;
 	}
-	filedes[0] = _open_osfhandle((int)h[0], O_NOINHERIT);
+	filedes[0] = _open_osfhandle((intptr_t)h[0], O_NOINHERIT);
 	if (filedes[0] < 0) {
 		CloseHandle(h[0]);
 		CloseHandle(h[1]);
 		return -1;
 	}
-	filedes[1] = _open_osfhandle((int)h[1], O_NOINHERIT);
+	filedes[1] = _open_osfhandle((intptr_t)h[1], O_NOINHERIT);
 	if (filedes[0] < 0) {
 		close(filedes[0]);
 		CloseHandle(h[1]);
@@ -1819,7 +1819,7 @@ void mingw_open_html(const char *unixpath)
 			const char *, const char *, const char *, INT);
 	T ShellExecute;
 	HMODULE shell32;
-	int r;
+	intptr_t r;
 
 	shell32 = LoadLibrary("shell32.dll");
 	if (!shell32)
@@ -1829,7 +1829,7 @@ void mingw_open_html(const char *unixpath)
 		die("cannot run browser");
 
 	printf("Launching default browser to display HTML ...\n");
-	r = (int)ShellExecute(NULL, "open", htmlpath, NULL, "\\", SW_SHOWNORMAL);
+	r = (intptr_t)ShellExecute(NULL, "open", htmlpath, NULL, "\\", SW_SHOWNORMAL);
 	FreeLibrary(shell32);
 	/* see the MSDN documentation referring to the result codes here */
 	if (r <= 32) {
diff --git a/compat/poll/poll.c b/compat/poll/poll.c
index a9b41d8..8941249 100644
--- a/compat/poll/poll.c
+++ b/compat/poll/poll.c
@@ -76,7 +76,7 @@
 
 #ifdef WIN32_NATIVE
 
-#define IsConsoleHandle(h) (((long) (h) & 3) == 3)
+#define IsConsoleHandle(h) (((intptr_t) (h) & 3) == 3)
 
 static BOOL
 IsSocketHandle (HANDLE h)
diff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c
index 06f3088..d8bde06 100644
--- a/compat/regex/regcomp.c
+++ b/compat/regex/regcomp.c
@@ -2577,7 +2577,7 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
     old_tree = NULL;
 
   if (elem->token.type == SUBEXP)
-    postorder (elem, mark_opt_subexp, (void *) (long) elem->token.opr.idx);
+    postorder (elem, mark_opt_subexp, (void *) (intptr_t) elem->token.opr.idx);
 
   tree = create_tree (dfa, elem, NULL, (end == -1 ? OP_DUP_ASTERISK : OP_ALT));
   if (BE (tree == NULL, 0))
@@ -3806,7 +3806,7 @@ create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
 static reg_errcode_t
 mark_opt_subexp (void *extra, bin_tree_t *node)
 {
-  int idx = (int) (long) extra;
+  int idx = (int) (intptr_t) extra;
   if (node->token.type == SUBEXP && node->token.opr.idx == idx)
     node->token.opt_subexp = 1;
 
diff --git a/compat/regex/regex_internal.h b/compat/regex/regex_internal.h
index 4184d7f..da12670 100644
--- a/compat/regex/regex_internal.h
+++ b/compat/regex/regex_internal.h
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdint.h>
 
 #if defined HAVE_LANGINFO_H || defined HAVE_LANGINFO_CODESET || defined _LIBC
 # include <langinfo.h>
diff --git a/compat/win32/pthread.h b/compat/win32/pthread.h
index 8ad1873..6ccfb7b 100644
--- a/compat/win32/pthread.h
+++ b/compat/win32/pthread.h
@@ -77,7 +77,7 @@ extern pthread_t pthread_self(void);
 
 static inline int pthread_exit(void *ret)
 {
-	ExitThread((DWORD)ret);
+	ExitThread((DWORD)(uintptr_t)ret);
 }
 
 typedef DWORD pthread_key_t;
diff --git a/compat/winansi.c b/compat/winansi.c
index 0ac3297..ca4c295 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -452,7 +452,7 @@ static HANDLE duplicate_handle(HANDLE hnd)
 	HANDLE hresult, hproc = GetCurrentProcess();
 	if (!DuplicateHandle(hproc, hnd, hproc, &hresult, 0, TRUE,
 			DUPLICATE_SAME_ACCESS))
-		die_lasterr("DuplicateHandle(%li) failed", (long) hnd);
+		die_lasterr("DuplicateHandle(%p) failed", hnd);
 	return hresult;
 }
 
diff --git a/pack-revindex.c b/pack-revindex.c
index 5c8376e..df02e9f 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -21,7 +21,7 @@ static int pack_revindex_hashsz;
 
 static int pack_revindex_ix(struct packed_git *p)
 {
-	unsigned long ui = (unsigned long)p;
+	uintptr_t ui = (uintptr_t)p;
 	int i;
 
 	ui = ui ^ (ui >> 16); /* defeat structure alignment */
diff --git a/sha1_file.c b/sha1_file.c
index c08c0cb..a534fda 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1966,11 +1966,11 @@ static struct delta_base_cache_entry {
 	enum object_type type;
 } delta_base_cache[MAX_DELTA_CACHE];
 
-static unsigned long pack_entry_hash(struct packed_git *p, off_t base_offset)
+static uintptr_t pack_entry_hash(struct packed_git *p, off_t base_offset)
 {
-	unsigned long hash;
+	uintptr_t hash;
 
-	hash = (unsigned long)p + (unsigned long)base_offset;
+	hash = (uintptr_t)p + base_offset;
 	hash += (hash >> 8) + (hash >> 16);
 	return hash % MAX_DELTA_CACHE;
 }
@@ -1978,7 +1978,7 @@ static unsigned long pack_entry_hash(struct packed_git *p, off_t base_offset)
 static struct delta_base_cache_entry *
 get_delta_base_cache_entry(struct packed_git *p, off_t base_offset)
 {
-	unsigned long hash = pack_entry_hash(p, base_offset);
+	uintptr_t hash = pack_entry_hash(p, base_offset);
 	return delta_base_cache + hash;
 }
 
-- 
2.1.1

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "Git for Windows" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Previous: Marat RadchenkoNext: Marat Radchenko
Message 13 of 30 in “MinGW(-W64) compilation”
  1. MinGW(-W64) compilationMarat Radchenko, Sep 30, 2014
  2. 01/14 MINGW: compat/mingw.h: do not attempt to redefine lseek on mingw-w64Marat Radchenko, Sep 30, 2014
  3. 02/14 MSVC: config.mak.uname: drop -D__USE_MINGW_ACCESS from CFLAGSMarat Radchenko, Sep 30, 2014
  4. 03/14 MINGW: compat/mingw.h: drop fork() definitionMarat Radchenko, Sep 30, 2014
  5. 04/14 MINGW: do not fail at redefining pid_t on MinGW-W64Marat Radchenko, Sep 30, 2014
  6. 05/14 MINGW: config.mak.uname: allow using cURL for non-msysGit buildsMarat Radchenko, Sep 30, 2014
  7. 06/14 MINGW: compat/winansi.c: do not redefine CONSOLE_FONT_INFOEXMarat Radchenko, Sep 30, 2014
  8. 07/14 Fix BASIC_LDFLAGS and COMPAT_CFLAGS for 64bit MinGW-w64Marat Radchenko, Sep 30, 2014
  9. 08/14 MINGW: git-compat-util.h: use inttypes.h for printf macrosMarat Radchenko, Sep 30, 2014
  10. 09/14 MINGW: config.mak.uname: reorganize MinGW settingsMarat Radchenko, Sep 30, 2014
  11. 10/14 Makefile: introduce CROSS_COMPILE variableMarat Radchenko, Sep 30, 2014
  12. 11/14 compat/nedmalloc/malloc.c.h: fix compilation under MinGW-W64Marat Radchenko, Sep 30, 2014
  13. 12/14 Fix pointer -> integer casts on IL32P64 systemsMarat Radchenko, Sep 30, 2014
  14. 13/14 git-compat-util.h: fix integer overflow on IL32P64 systemsMarat Radchenko, Sep 30, 2014
  15. 14/14 MINGW: config.mak.uname: auto-detect MinGW build from compilerMarat Radchenko, Sep 30, 2014
  16. Duy NguyenSep 30, 2014
  17. Marat RadchenkoOct 6, 2014
  18. Johannes SixtOct 6, 2014
  19. Junio C HamanoOct 7, 2014
  20. Johannes SixtOct 7, 2014
  21. Thomas BraunOct 7, 2014
  22. Marat RadchenkoOct 8, 2014
  23. Johannes SchindelinOct 8, 2014
  24. Marat RadchenkoOct 8, 2014
  25. Johannes SchindelinOct 8, 2014
  26. Thomas BraunOct 8, 2014
  27. Johannes SchindelinOct 8, 2014
  28. Johannes SchindelinOct 8, 2014
  29. Marat RadchenkoOct 8, 2014
  30. Johannes SchindelinOct 8, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.