[PATCH v4 4/4] add predefine_min() and use it for __{WCHAR,WINT}_MIN__

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



wchar_t & wint_t seems to be the only integer types needing
the _MIN__ macros.

Extend predefine_ctype() to handle these and use it to define
__WCHAR_MIN__ & __WINT_MIN__.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 lib.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib.c b/lib.c
index ed2f5e3dd..e4a65e937 100644
--- a/lib.c
+++ b/lib.c
@@ -1172,6 +1172,19 @@ static void predefined_max(const char *name, struct symbol *type)
 	predefine(buf, 1, "%#llx%s", max, suffix);
 }
 
+static void predefined_min(const char *name, struct symbol *type)
+{
+	const char *suffix = builtin_type_suffix(type);
+	char buf[32];
+
+	snprintf(buf, sizeof(buf), "__%s_MIN__", name);
+
+	if (is_signed_type(type))
+		predefine(buf, 1, "(-__%s_MAX__ - 1)", name);
+	else
+		predefine(buf, 1, "0%s", suffix);
+}
+
 static void predefined_type(const char *name, struct symbol *type)
 {
 	const char *typename = builtin_typename(type);
@@ -1188,6 +1201,8 @@ static void predefined_ctype(const char *name, struct symbol *type, int flags)
 	}
 	if (flags & PTYPE_MAX)
 		predefined_max(name, type);
+	if (flags & PTYPE_MIN)
+		predefined_min(name, type);
 	if (flags & PTYPE_TYPE)
 		predefined_type(name, type);
 	if (flags & PTYPE_WIDTH)
@@ -1242,8 +1257,8 @@ static void predefined_macros(void)
 	predefined_ctype("SHORT",     &short_ctype, PTYPE_SIZEOF);
 	predefined_ctype("SHRT",      &short_ctype, PTYPE_MAX|PTYPE_WIDTH);
 	predefined_ctype("SCHAR",     &schar_ctype, PTYPE_MAX|PTYPE_WIDTH);
-	predefined_ctype("WCHAR",      wchar_ctype, PTYPE_ALL_T|PTYPE_TYPE);
-	predefined_ctype("WINT",        wint_ctype, PTYPE_ALL_T|PTYPE_TYPE);
+	predefined_ctype("WCHAR",      wchar_ctype, PTYPE_ALL_T|PTYPE_MIN|PTYPE_TYPE);
+	predefined_ctype("WINT",        wint_ctype, PTYPE_ALL_T|PTYPE_MIN|PTYPE_TYPE);
 	predefined_ctype("CHAR16",   &ushort_ctype, PTYPE_TYPE);
 	predefined_ctype("CHAR32",     &uint_ctype, PTYPE_TYPE);
 
-- 
2.20.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux