[PATCH 10/13] format-check: add a function to check the type of floats

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

 



This checking is currently done by check_assignment_types()
for all numeric types but this is not adequate because we
want to have a better control over what is allowed or not

So, add a custom checking function, currently just checking
if the argument is one of the floating-point types.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 verify-format.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/verify-format.c b/verify-format.c
index 34c3db96fe3a..6bcbfdfef1b4 100644
--- a/verify-format.c
+++ b/verify-format.c
@@ -106,6 +106,27 @@ static int printf_fmt_numtype(struct format_type *fmt,
 	return check_assignment_types(fmt->type, expr, typediff);
 }
 
+static const char *check_printf_float(struct format_type *fmt, struct symbol *source)
+{
+	const char *typediff = "different base types";
+	struct symbol *target = fmt->type;
+	struct symbol *base;
+
+	if (type_class(source, &base) != CLASS_FLOAT)
+		return typediff;
+	if (base == target)
+		return NULL;
+	return typediff;
+}
+
+static int printf_fmt_float(struct format_type *fmt,
+			      struct expression **expr,
+			      struct symbol *ctype,
+			      const char **typediff)
+{
+	return !(*typediff = check_printf_float(fmt, ctype));
+}
+
 // For 's' & 'S' specifiers
 static const char *check_printf_string(struct format_type *fmt, struct symbol *source)
 {
@@ -310,7 +331,7 @@ static struct format_type *parse_printf_get_fmt(struct format_type *type,
 		break;
 	case 'e': case 'E': case 'f': case 'F': case 'g': case 'G':
 	case 'a': case 'A':
-		type->test = printf_fmt_numtype;
+		type->test = printf_fmt_float;
 		switch (szmod) {
 		case LEN_none:
 			type->type = &double_ctype;
-- 
2.28.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