diff mbox series

[08/13] format-check: add a function to check to type of pointers

Message ID 20201013232231.10349-9-luc.vanoostenryck@gmail.com (mailing list archive)
State Deferred, archived
Headers show
Series format-check: add specific type checking | expand

Commit Message

Luc Van Oostenryck Oct. 13, 2020, 11:22 p.m. UTC
This checking is currently done by check_assignment_types()
but as an extension, specific pointer types will be checked.

So, add a custom checking function, currently accepting any
pointer type.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 verify-format.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/verify-format.c b/verify-format.c
index 1b40b2c796a2..cd55a49e0676 100644
--- a/verify-format.c
+++ b/verify-format.c
@@ -181,12 +181,24 @@  static int printf_fmt_length(struct format_type *fmt,
 	return !(*typediff = check_printf_length(fmt, ctype));
 }
 
+// For 'p' specifiers
+static const char *check_printf_pointer(struct format_type *fmt, struct symbol *source)
+{
+	const char *typediff = "different base types";
+	struct symbol *base;
+
+	if (type_class(source, &base) != CLASS_PTR)
+		return typediff;
+	// FIXME: check or ignore address spaces
+	return NULL;
+}
+
 static int printf_fmt_pointer(struct format_type *fmt,
 			      struct expression **expr,
 			      struct symbol *ctype,
 			      const char **typediff)
 {
-	return check_assignment_types(fmt->type, expr, typediff);
+	return !(*typediff = check_printf_pointer(fmt, ctype));
 }
 
 static int printf_fmt_print_pointer(struct format_type *fmt,