Re: latest printf code

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

 



On Mon, Nov 04, 2019 at 10:46:44PM +0100, Luc Van Oostenryck wrote:
> On Fri, Nov 01, 2019 at 04:36:51PM +0000, Ben Dooks wrote:
> > I've put the latest code up at:
> > 
> >  https://github.com/bjdooks-ct/sparse bjdooks/printf20
> > 
> > I think it has all the issues dealt with.
> > 
> > I can't currently post or do a final test as away from work laptop.
> 
> Thank you.
> 
> I've a few more remarks about formatting or naming and
> also some simplifications I would like you make.

In some of the checks you're calling evaluate_expression() and
degenerate() but this is done on the arguments and these have
already been evaluated (and degenerated in evaluate_arguments().
It's thus not needed to do it again, expr->ctype already contains
the right type or can be null (or can be &bad_ctype).

>From e6cf4b8c20f3d53d92df55173e786fdf81d5f0d9 Mon Sep 17 00:00:00 2001
From: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
Date: Mon, 4 Nov 2019 18:40:12 +0100
Subject: [PATCH 6/7] evaluate() & degenerate() are already done

---
 evaluate.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/evaluate.c b/evaluate.c
index fc340c2c3..d27499ccf 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -2583,16 +2583,14 @@ static int parse_format_printf_argfield(const char **fmtptr,
 	}
 
 	/* check the value we got was int/uint type */
-	ctype = evaluate_expression(expr);
+	ctype = expr->ctype;
 	if (ctype) {
-		struct symbol *source, *target = &int_ctype;
+		struct symbol *target = &int_ctype;
 
-		source = degenerate(expr);
-
-		if (source != &int_ctype && source != &uint_ctype) {
+		if (ctype != &int_ctype && ctype != &uint_ctype) {
 			warning(expr->pos, "incorrect type for %s argument %d", which, argpos);
 			info(expr->pos, "   expected %s", show_typename(target));
-			info(expr->pos, "   got %s", show_typename(source));
+			info(expr->pos, "   got %s", show_typename(ctype));
 		}
 	}
 
@@ -2666,7 +2664,7 @@ static int parse_format_printf(const char **fmtstring,
 		type = &printf_fmt_ptr_ref;	/* probably some extension */
 
 	if (type) {
-		struct symbol *ctype, *source, *target = NULL;
+		struct symbol *ctype, *target = NULL;
 		const char *typediff = "different types";
 		int ret;
 
@@ -2678,11 +2676,10 @@ static int parse_format_printf(const char **fmtstring,
 			return 0;
 		}
 
-		ctype = evaluate_expression(expr);
+		ctype = expr->ctype;
 		if (!ctype)
 			return -3;
 
-		source = degenerate(expr);
 		ret = type->test(type, &expr, ctype, &target, &typediff);
 		if (!target)	/* shouldn't happen, but catch anyway */
 			return -4;
@@ -2690,7 +2687,7 @@ static int parse_format_printf(const char **fmtstring,
 		if (ret == 0) {
 			warning(expr->pos, "incorrect type in argument %d (%s)", pos, typediff);
 			info(expr->pos, "   expected %s", show_typename(target));
-			info(expr->pos, "   got %s", show_typename(source));
+			info(expr->pos, "   got %s", show_typename(ctype));
 		}
 	} else {
 		/* try and find the end of this format string by looking for a space*/
-- 
2.23.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