From patchwork Wed Apr 3 15:35:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 10884025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97500922 for ; Wed, 3 Apr 2019 15:35:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F7A128770 for ; Wed, 3 Apr 2019 15:35:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73D2F28795; Wed, 3 Apr 2019 15:35:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBE1728770 for ; Wed, 3 Apr 2019 15:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726264AbfDCPf5 (ORCPT ); Wed, 3 Apr 2019 11:35:57 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:51735 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725959AbfDCPf5 (ORCPT ); Wed, 3 Apr 2019 11:35:57 -0400 Received: from [167.98.27.226] (helo=rainbowdash.codethink.co.uk) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1hBhve-0005VP-Ov; Wed, 03 Apr 2019 16:35:54 +0100 Received: from ben by rainbowdash.codethink.co.uk with local (Exim 4.92) (envelope-from ) id 1hBhve-00067l-4A; Wed, 03 Apr 2019 16:35:54 +0100 From: Ben Dooks To: linux-sparse@vger.kernel.org Cc: Ben Dooks Subject: [PATCH 6/6] evaluate: correct order of arguments Date: Wed, 3 Apr 2019 16:35:52 +0100 Message-Id: <20190403153552.23461-7-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403153552.23461-1-ben.dooks@codethink.co.uk> References: <20190403153552.23461-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ben Dooks The original update to evaluate.c did the va-arg checking before the standard checks. This is due to degernate() removing expr->string so save the string before the loop and then use it afterwards. -> to push back into evaluate.c if no other options available. --- evaluate.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/evaluate.c b/evaluate.c index a21bc3f..29c3470 100644 --- a/evaluate.c +++ b/evaluate.c @@ -2685,20 +2685,14 @@ static int parse_format_printf(const char **fmtstring, return 1; } -/* attempt to run through a printf format string and work out the types - * it specifies. The format is parsed from the __attribute__(format()) - * in the parser code which stores the positions of the message and arg - * start in the ctype. - */ -static void evaluate_format_printf(struct symbol *fn, struct expression_list *head) +static const char *get_printf_fmt(struct symbol *fn, struct expression_list *head) { - struct format_state state = { }; struct expression *expr; - const char *fmt_string = NULL; + const char *fmt_string; expr = get_expression_n(head, fn->ctype.printf_msg-1); if (!expr) - return; + return NULL; if (expr->string && expr->string->length) fmt_string = expr->string->data; if (!fmt_string) { @@ -2709,6 +2703,23 @@ static void evaluate_format_printf(struct symbol *fn, struct expression_list *he fmt_string = sym->initializer->string->data; } + return fmt_string; +} + +/* attempt to run through a printf format string and work out the types + * it specifies. The format is parsed from the __attribute__(format()) + * in the parser code which stores the positions of the message and arg + * start in the ctype. + */ +static void evaluate_format_printf(const char *fmt_string, struct symbol *fn, struct expression_list *head) +{ + struct format_state state = { }; + struct expression *expr; + + expr = get_expression_n(head, fn->ctype.printf_msg-1); + if (!expr) + return; + state.expr = expr; state.va_start = fn->ctype.printf_va_start; state.arg_index = fn->ctype.printf_va_start; @@ -2737,14 +2748,16 @@ static int evaluate_arguments(struct symbol *fn, struct expression_list *head) { struct expression *expr; struct symbol_list *argument_types = fn->arguments; + static const char *fmt_string = NULL; struct symbol *argtype; int i = 1; /* do this first, otherwise the arugment info may get lost or changed - * later on in the evaluation loop. + * later on in the evaluation loop by degenerate() */ if (Wformat && fn->ctype.printf_va_start) - evaluate_format_printf(fn, head); + fmt_string =get_printf_fmt(fn, head); + PREPARE_PTR_LIST(argument_types, argtype); FOR_EACH_PTR (head, expr) { @@ -2782,6 +2795,10 @@ static int evaluate_arguments(struct symbol *fn, struct expression_list *head) NEXT_PTR_LIST(argtype); } END_FOR_EACH_PTR(expr); FINISH_PTR_LIST(argtype); + + if (Wformat && fn->ctype.printf_va_start) + evaluate_format_printf(fmt_string, fn, head); + return 1; }