Merge branch 'dev'
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8978c3b..e92a621 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,6 @@
 cmake_minimum_required(VERSION 2.6...3.0.2)
 
-project(xbyak LANGUAGES CXX VERSION 6.01)
+project(xbyak LANGUAGES CXX VERSION 6.02)
 
 file(GLOB headers xbyak/*.h)
 
diff --git a/meson.build b/meson.build
index a1e69a5..a29dff6 100644
--- a/meson.build
+++ b/meson.build
@@ -5,7 +5,7 @@
 project(
 	'xbyak',
 	'cpp',
-	version: '6.01',
+	version: '6.02',
 	license: 'BSD-3-Clause',
 	default_options: 'b_ndebug=if-release'
 )
diff --git a/readme.md b/readme.md
index 4c78f7b..67ab861 100644
--- a/readme.md
+++ b/readme.md
@@ -1,6 +1,6 @@
 [![Build Status](https://github.com/herumi/xbyak/actions/workflows/main.yml/badge.svg)](https://github.com/herumi/xbyak/actions/workflows/main.yml)
 
-# Xbyak 6.01 ; JIT assembler for x86(IA32), x64(AMD64, x86-64) by C++
+#lXbyak 6.02 ; JIT assembler for x86(IA32), x64(AMD64, x86-64) by C++
 
 ## Abstract
 
@@ -19,6 +19,8 @@
 If you want to use them, then specify `-fno-operator-names` option to gcc/clang.
 
 ### News
+- strictly check address offset disp32 in a signed 32-bit integer. e.g., `ptr[(void*)0xffffffff]` causes an error.
+  - define `XBYAK_OLD_DISP_CHECK` if you need an old check, but the option will be remoevd.
 - add `jmp(mem, T_FAR)`, `call(mem, T_FAR)` `retf()` for far absolute indirect jump.
 - vnni instructions such as vpdpbusd supports vex encoding.
 - (break backward compatibility) `push(byte, imm)` (resp. `push(word, imm)`) forces to cast `imm` to 8(resp. 16) bit.
@@ -452,6 +454,7 @@
 * define **XBYAK_UNDEF_JNL** if Bessel function jnl is defined as macro.
 * define **XBYAK_NO_EXCEPTION** for a compiler option `-fno-exceptions`.
 * define **XBYAK_USE_MEMFD** on Linux then /proc/self/maps shows the area used by xbyak.
+* define **XBYAK_OLD_DISP_CHECK** if the old disp check is necessary (deprecated in the future).
 
 ## Sample
 
diff --git a/readme.txt b/readme.txt
index 460da05..216190a 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,5 +1,5 @@
 

-    C++用x86(IA-32), x64(AMD64, x86-64) JITアセンブラ Xbyak 6.01

+    C++用x86(IA-32), x64(AMD64, x86-64) JITアセンブラ Xbyak 6.02

 

 -----------------------------------------------------------------------------

 ◎概要

diff --git a/test/address.cpp b/test/address.cpp
index e713b5a..bb8cd4c 100644
--- a/test/address.cpp
+++ b/test/address.cpp
@@ -93,7 +93,7 @@
 					}
 					if (isFirst) {
 						if (isJIT) printf("(void*)");
-						printf("0x%08X", disp);
+						printf("%d", disp);
 					} else {
 						if (disp >= 0) {
 							putchar('+');
diff --git a/test/make_nm.cpp b/test/make_nm.cpp
index 8af0670..c26394a 100644
--- a/test/make_nm.cpp
+++ b/test/make_nm.cpp
@@ -1269,6 +1269,10 @@
 		put("mov", REG64, "0x12345678", "0x12345678");
 		put("mov", REG64, "0xffffffff12345678LL", "0xffffffff12345678");
 		put("mov", REG32e|REG16|REG8|RAX|EAX|AX|AL, IMM);
+
+		put("mov", EAX, "ptr[(void*)-1]", "[-1]");
+		put("mov", EAX, "ptr[(void*)0x7fffffff]", "[0x7fffffff]");
+		put("mov", EAX, "ptr[(void*)0xffffffffffffffff]", "[0xffffffffffffffff]");
 	}
 	void putEtc() const
 	{
diff --git a/test/misc.cpp b/test/misc.cpp
index 3b10c99..0e1c3f4 100644
--- a/test/misc.cpp
+++ b/test/misc.cpp
@@ -79,6 +79,17 @@
 					CYBOZU_TEST_NO_EXCEPTION(mov(af[eax], v));
 				}
 			}
+#ifdef XBYAK64
+			CYBOZU_TEST_NO_EXCEPTION(mov(rax, ptr[(void*)0x7fffffff]));
+			CYBOZU_TEST_EXCEPTION(mov(rax, ptr[(void*)0x17fffffff]), Xbyak::Error);
+#ifdef XBYAK_OLD_DISP_CHECK
+			CYBOZU_TEST_NO_EXCEPTION(mov(rax, ptr[(void*)0x80000000]));
+			CYBOZU_TEST_NO_EXCEPTION(mov(rax, ptr[(void*)0xffffffff]));
+#else
+			CYBOZU_TEST_EXCEPTION(mov(rax, ptr[(void*)0x80000000]), Xbyak::Error);
+			CYBOZU_TEST_EXCEPTION(mov(rax, ptr[(void*)0xffffffff]), Xbyak::Error);
+#endif
+#endif
 		}
 	} code;
 }
diff --git a/xbyak/xbyak.h b/xbyak/xbyak.h
index 637ea12..b99ebfa 100644
--- a/xbyak/xbyak.h
+++ b/xbyak/xbyak.h
@@ -142,7 +142,7 @@
 
 enum {
 	DEFAULT_MAX_CODE_SIZE = 4096,
-	VERSION = 0x6010 /* 0xABCD = A.BC(D) */
+	VERSION = 0x6020 /* 0xABCD = A.BC(D) */
 };
 
 #ifndef MIE_INTEGER_TYPE_DEFINED
@@ -1786,8 +1786,15 @@
 	{
 		uint64_t disp64 = e.getDisp();
 #ifdef XBYAK64
+#ifdef XBYAK_OLD_DISP_CHECK
+		// treat 0xffffffff as 0xffffffffffffffff
 		uint64_t high = disp64 >> 32;
 		if (high != 0 && high != 0xFFFFFFFF) XBYAK_THROW(ERR_OFFSET_IS_TOO_BIG)
+#else
+		// displacement should be a signed 32-bit value, so also check sign bit
+		uint64_t high = disp64 >> 31;
+		if (high != 0 && high != 0x1FFFFFFFF) XBYAK_THROW(ERR_OFFSET_IS_TOO_BIG)
+#endif
 #endif
 		uint32_t disp = static_cast<uint32_t>(disp64);
 		const Reg& base = e.getBase();
diff --git a/xbyak/xbyak_mnemonic.h b/xbyak/xbyak_mnemonic.h
index 09f2dcf..4676b56 100644
--- a/xbyak/xbyak_mnemonic.h
+++ b/xbyak/xbyak_mnemonic.h
@@ -1,4 +1,4 @@
-const char *getVersionString() const { return "6.01"; }
+const char *getVersionString() const { return "6.02"; }
 void adc(const Operand& op, uint32_t imm) { opRM_I(op, imm, 0x10, 2); }
 void adc(const Operand& op1, const Operand& op2) { opRM_RM(op1, op2, 0x10); }
 void adcx(const Reg32e& reg, const Operand& op) { opGen(reg, op, 0xF6, 0x66, isREG32_REG32orMEM, NONE, 0x38); }