From patchwork Thu Apr 4 18:24:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 10886049 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 6620A15AC for ; Thu, 4 Apr 2019 18:24:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5087A28AD5 for ; Thu, 4 Apr 2019 18:24:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44A7428AD7; Thu, 4 Apr 2019 18:24:10 +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 B04C128AC2 for ; Thu, 4 Apr 2019 18:24:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729526AbfDDSYJ (ORCPT ); Thu, 4 Apr 2019 14:24:09 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:59765 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729286AbfDDSYJ (ORCPT ); Thu, 4 Apr 2019 14:24:09 -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 1hC71y-0002d3-1q; Thu, 04 Apr 2019 19:24:06 +0100 Received: from ben by rainbowdash.codethink.co.uk with local (Exim 4.92) (envelope-from ) id 1hC71x-0003Tw-Ot; Thu, 04 Apr 2019 19:24:05 +0100 From: Ben Dooks To: linux-sparse@vger.kernel.org Cc: Ben Dooks Subject: [RFC v3 1/4] parse: initial parsing of __attribute__((format)) Date: Thu, 4 Apr 2019 19:24:00 +0100 Message-Id: <20190404182403.13192-2-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190404182403.13192-1-ben.dooks@codethink.co.uk> References: <20190404182403.13192-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 Add code to parse the __attribute__((format)) used to indicate that a variadic function takes a printf-style format string and where those are. Save the data in ctype ready for checking when such an function is encoutered. Signed-off-by: Ben Dooks --- Fixes since v1: - moved to using ctype in base_type to store infromation - fixed formatting issues - updated check for bad format arguments - reduced the line count to unsigned short to save space Fixes since v2: - correctly use the decl->ctype to store printf information - fixed issues with checking format positions for va_list code - parse but ignore scanf formatting for now Fixes since v4: - deal with function pointers losing format info Fixes since v5: - remove function pointer attribute support --- parse.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- symbol.h | 2 ++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/parse.c b/parse.c index f291e24..583a82c 100644 --- a/parse.c +++ b/parse.c @@ -87,7 +87,7 @@ static attr_t attribute_address_space, attribute_context, attribute_designated_init, attribute_transparent_union, ignore_attribute, - attribute_mode, attribute_force; + attribute_mode, attribute_force, attribute_format; typedef struct symbol *to_mode_t(struct symbol *); @@ -136,6 +136,11 @@ static void asm_modifier_inline(struct token *token, unsigned long *mods) asm_modifier(token, mods, MOD_INLINE); } +/* the types of printf style formatting from __attribute__((format)) */ +enum { + FmtPrintf = 0, FmtScanf, +}; + static struct symbol_op typedef_op = { .type = KW_MODIFIER, .declarator = typedef_specifier, @@ -386,6 +391,10 @@ static struct symbol_op attr_force_op = { .attribute = attribute_force, }; +static struct symbol_op attr_format = { + .attribute = attribute_format, +}; + static struct symbol_op address_space_op = { .attribute = attribute_address_space, }; @@ -445,6 +454,16 @@ static struct symbol_op mode_word_op = { .to_mode = to_word_mode }; +static struct symbol_op attr_printf_op = { + .type = KW_FORMAT, + .class = FmtPrintf, +}; + +static struct symbol_op attr_scanf_op = { + .type = KW_FORMAT, + .class = FmtScanf, +}; + /* Using NS_TYPEDEF will also make the keyword a reserved one */ static struct init_keyword { const char *name; @@ -570,6 +589,10 @@ static struct init_keyword { {"externally_visible", NS_KEYWORD, .op = &ext_visible_op }, {"__externally_visible__", NS_KEYWORD, .op = &ext_visible_op }, + { "format", NS_KEYWORD, .op = &attr_format }, + { "printf", NS_KEYWORD, .op = &attr_printf_op }, + { "scanf", NS_KEYWORD, .op = &attr_scanf_op }, + { "mode", NS_KEYWORD, .op = &mode_op }, { "__mode__", NS_KEYWORD, .op = &mode_op }, { "QI", NS_KEYWORD, .op = &mode_QI_op }, @@ -1172,6 +1195,59 @@ static struct token *attribute_address_space(struct token *token, struct symbol return token; } +static int invalid_printf_format_args(long long start, long long at) +{ + return start < 0 || at < 0 || (start == at && start > 0) || + (start == 0 && at == 0); +} + +static struct token *attribute_format(struct token *token, struct symbol *attr, struct decl_state *ctx) +{ + struct expression *args[3]; + struct symbol *fmt_sym = NULL; + + /* expecting format ( type, start, va_args at) */ + + token = expect(token, '(', "after format attribute"); + if (token_type(token) == TOKEN_IDENT) + fmt_sym = lookup_keyword(token->ident, NS_KEYWORD); + if (fmt_sym) + if (!fmt_sym->op || fmt_sym->op->type != KW_FORMAT) + fmt_sym = NULL; + + token = conditional_expression(token, &args[0]); + token = expect(token, ',', "format attribute type"); + token = conditional_expression(token, &args[1]); + token = expect(token, ',', "format attribute type position"); + token = conditional_expression(token, &args[2]); + token = expect(token, ')', "format attribute arg position"); + + if (!fmt_sym || !args[0] || !args[1] || !args[2]) { + warning(token->pos, "incorrect format attribute"); + } else if (fmt_sym->op->class != FmtPrintf) { + /* skip anything that isn't printf for the moment */ + warning(token->pos, "only printf format attribute supported"); + } else { + long long start, at; + + start = get_expression_value(args[2]); + at = get_expression_value(args[1]); + + if (invalid_printf_format_args(start, at)) { + warning(token->pos, "bad format positions"); + } else if (start == 0) { + /* nothing to do here, is va_list function */ + } else if (start < at) { + warning(token->pos, "format cannot be after va_args"); + } else { + ctx->ctype.printf_va_start = start; + ctx->ctype.printf_msg = at; + } + } + + return token; +} + static struct symbol *to_QI_mode(struct symbol *ctype) { if (ctype->ctype.base_type != &int_type) @@ -2981,6 +3057,9 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis if (!(decl->ctype.modifiers & MOD_STATIC)) decl->ctype.modifiers |= MOD_EXTERN; + + base_type->ctype.printf_msg = decl->ctype.printf_msg; + base_type->ctype.printf_va_start = decl->ctype.printf_va_start; } else if (base_type == &void_ctype && !(decl->ctype.modifiers & MOD_EXTERN)) { sparse_error(token->pos, "void declaration"); } diff --git a/symbol.h b/symbol.h index ac43b31..7bb6f29 100644 --- a/symbol.h +++ b/symbol.h @@ -86,6 +86,7 @@ enum keyword { KW_SHORT = 1 << 7, KW_LONG = 1 << 8, KW_EXACT = 1 << 9, + KW_FORMAT = 1 << 10, }; struct context { @@ -103,6 +104,7 @@ struct ctype { struct context_list *contexts; struct ident *as; struct symbol *base_type; + unsigned short printf_va_start, printf_msg; }; struct decl_state { From patchwork Thu Apr 4 18:24:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 10886053 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 D30C715AC for ; Thu, 4 Apr 2019 18:24:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B94C828AC2 for ; Thu, 4 Apr 2019 18:24:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACBF828AD5; Thu, 4 Apr 2019 18:24:13 +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 C287928AC2 for ; Thu, 4 Apr 2019 18:24:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729286AbfDDSYM (ORCPT ); Thu, 4 Apr 2019 14:24:12 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:59768 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728762AbfDDSYM (ORCPT ); Thu, 4 Apr 2019 14:24:12 -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 1hC71y-0002d4-2q; Thu, 04 Apr 2019 19:24:06 +0100 Received: from ben by rainbowdash.codethink.co.uk with local (Exim 4.92) (envelope-from ) id 1hC71x-0003Tz-Pj; Thu, 04 Apr 2019 19:24:05 +0100 From: Ben Dooks To: linux-sparse@vger.kernel.org Cc: Ben Dooks Subject: [RFC v3 2/4] evaluate: check variadic argument types against formatting info Date: Thu, 4 Apr 2019 19:24:01 +0100 Message-Id: <20190404182403.13192-3-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190404182403.13192-1-ben.dooks@codethink.co.uk> References: <20190404182403.13192-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 The variadic argumnet code did not check any of the variadic arguments as it did not previously know the possible type. Now we have the possible formatting information stored in the ctype, we can do some checks on the printf formatting types. Signed-off-by: Ben Dooks --- Fixes since v1: - Split out the format-string -> symbol code - Use symbol_list for the symbols from format parsing - Changed to follow the new parsing code and ctype use - Merged the unsigned-int/long types together Fixes since v2: - Check for printf_va_start before checking variadic-list - Tidy the type code and fix a couple of bugs with %l and %ll - Fix function names in working through printf arguments. - Tidy documentation Fixes since v3: - Added positional arguments - Also added precision and width specifiers Fixes since v4: - Stop copying the format string - Removed void data pointer - Suggested code cleanups Fixes since v5: - Rewritten format parsing code - Updates for handling kernel printk formatting - Fix parsing issues with ')' characters Fixes since v6; - Evaluate aftre all standard args are done - Fix 'L' parsing Fixes since v7: - Updated comment format - Remove static variable from get_fmt() Notes: - %p still generates an address-space mismatch - how do we deal with the kernel's attempt to make printk format all types? hack: ) will end format too --- evaluate.c | 443 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 443 insertions(+) diff --git a/evaluate.c b/evaluate.c index d9cd41d..d3d9c8e 100644 --- a/evaluate.c +++ b/evaluate.c @@ -2319,13 +2319,452 @@ static struct symbol *evaluate_alignof(struct expression *expr) return size_t_ctype; } +struct format_type { + const char *format; + int (*test)(struct format_type *fmt, struct expression **expr, struct symbol *ctype, struct symbol **target, const char **typediff); + struct symbol *data; +}; + +struct format_state { + struct expression *expr; + unsigned int va_start; + unsigned int fmt_index; + unsigned int arg_index; + unsigned int used_position: 1; +}; + +static int printf_fmt_numtype(struct format_type *fmt, struct expression **expr, struct symbol *ctype, struct symbol **target, const char **typediff) +{ + struct symbol *type = fmt->data; + *target = type; + return ctype == type; +} + +static int printf_fmt_string(struct format_type *fmt, struct expression **expr, struct symbol *ctype, struct symbol **target, const char **typediff) +{ + *target = &string_ctype; + return check_assignment_types(*target, expr, typediff); +} + +static int printf_fmt_pointer(struct format_type *fmt, struct expression **expr, struct symbol *ctype, struct symbol **target, const char **typediff) +{ + *target = &ptr_ctype; + return check_assignment_types(*target, expr, typediff); +} + +static int printf_fmt_print_pointer(struct format_type *fmt, struct expression **expr, struct symbol *ctype, struct symbol **target, const char **typediff) +{ + int ret; + *target = &ptr_ctype; + ret =check_assignment_types(*target, expr, typediff); + if (ret == 0) { + /* if just printing, ignore address-space mismatches */ + if (strcmp(*typediff, "different address spaces") == 0) + ret = 1; + } + return ret; +} + +static struct format_type printf_fmt_ptr_ref = { "p", .test = printf_fmt_pointer, }; + +static struct expression *get_expression_n(struct expression_list *args, int nr) +{ + return ptr_list_nth_entry((struct ptr_list *)args, nr); +} + +static int is_float_spec(char t) +{ + return t == 'f' || t == 'g' || t == 'F' || t == 'G'; +} + +static struct format_type *parse_printf_get_fmt(struct format_type *type, const char *msg, const char **msgout) +{ + const char *ptr = msg; + int szmod=0; + + type->test = NULL; + *msgout = ptr; + + if (*ptr == 's') { + ptr++; + type->test = printf_fmt_string; + } else if (*ptr == 'c') { + ptr++; + type->test = printf_fmt_numtype; + type->data = &char_ctype; + } else if (*ptr == 'p') { + ptr++; + type->test = printf_fmt_print_pointer; + //todo - check if there's anything after these? + if (*ptr == 'x' || *ptr == 'X') { + ptr++; + } else if (isalpha(*ptr)) { + // probably sxomething that /is/ being de-referenced + ptr++; + type->test = printf_fmt_pointer; + } + } else if (*ptr == 'z') { + ptr++; + if (*ptr == 'd') { + ptr++; + type->test = printf_fmt_numtype; + type->data = &long_ctype; + } else if (*ptr == 'u' || *ptr == 'x') { + ptr++; + type->test = printf_fmt_numtype; + type->data = &ulong_ctype; + } + } else { + if (*ptr == 'l') { + szmod++; + ptr++; + if (*ptr == 'l') { + szmod++; + ptr++; + } + } else { + if (*ptr == 'h') { // short/char to int + szmod = -1; + ptr++; + if (*ptr == 'h') // promotion from char + ptr++; + } + if (*ptr == 't') { // ptrdiff_t + szmod = 2; + ptr++; + } + if (*ptr == 'j') { // intmax_t + // todo - replace iwth intmax_ctype when added + szmod = 1; + ptr++; + } + } + + if (*ptr == 'x' || *ptr == 'X' || *ptr == 'u' || *ptr == 'o') { + ptr++; + type->test = printf_fmt_numtype; + switch (szmod) { + case -1: + type->data = &ushort_ctype; + break; + case 0: + type->data = &uint_ctype; + break; + case 1: + type->data = &ulong_ctype; + break; + case 2: + type->data = &ullong_ctype; + break; + default: + type->test = NULL; + } + } else if (*ptr == 'i' || *ptr == 'd') { + ptr++; + type->test = printf_fmt_numtype; + switch (szmod) { + case -1: + type->data = &short_ctype; + break; + case 0: + type->data = &int_ctype; + break; + case 1: + type->data = &long_ctype; + break; + case 2: + type->data = &llong_ctype; + break; + default: + type->test = NULL; + } + } else if (*ptr == 'L' && is_float_spec(ptr[1])) { + type->test = printf_fmt_numtype; + type->data = &ldouble_ctype; + ptr += 2; + } else if (is_float_spec(*ptr)) { + type->test = printf_fmt_numtype; + type->data = &double_ctype; + ptr++; + } else if (*ptr == 'n') { /* pointer to an de-referenced int/etc */ + // todo - we should construct pointer to int/etc // + // also should not have any flags or widths for this + type->test = printf_fmt_pointer; + ptr++; + } else { + // anything else here? + } + } + + if (type->test == NULL) + return NULL; + + *msgout = ptr; + return type; +} + +static int is_printf_flag(char ch) +{ + return ch == '0' || ch == '+' || ch == '-' || ch == ' ' || ch == '#'; +} + +static int printf_check_position(const char **fmt) +{ + const char *ptr= *fmt; + + if (!isdigit(*ptr)) + return -1; + while (isdigit(*ptr)) + ptr++; + if (*ptr == '$') { + const char *pos = *fmt; + *fmt = ptr+1; + return strtoul(pos, NULL, 10); + } + return -1; +} + +static void parse_format_printf_checkpos(struct format_state *state, const char *which) +{ + if (state->used_position) + warning(state->expr->pos, + "format %d: %s: no position specified", + state->arg_index-1, which); +} + +static int parse_format_printf_argfield(const char **fmtptr, struct format_state *state, struct expression_list *args, int *pos, const char *which) +{ + struct expression *expr; + struct symbol *ctype; + const char *fmt = *fmtptr; + int argpos = -1; + + /* check for simple digit-string width/precision specifier first */ + if (*fmt != '*') { + while (isdigit(*fmt)) + fmt++; + *fmtptr = fmt; + return 0; + } + + fmt++; + argpos = printf_check_position(&fmt); + + if (argpos > 0) { + argpos += state->va_start - 1; + state->used_position = 1; + } else { + argpos = (*pos)++; + state->arg_index++; + parse_format_printf_checkpos(state, which); + } + + *fmtptr = fmt; + expr = get_expression_n(args, argpos-1); + if (!expr) { + warning(state->expr->pos, "%s: no argument at position %d", which, argpos); + return 1; + } + + /* check the vale we got was int/uint type */ + ctype = evaluate_expression(expr); + if (ctype) { + struct symbol *source, *target = &int_ctype; + + source = degenerate(expr); + + if (source != &int_ctype && source != &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)); + } + } + + return 0; +} + +/* + * printf format parsing code + * + * this code currently does not: + * - check castable types (such as int vs long vs long long) + * - validate all arguments specified are also used... + */ +static int parse_format_printf(const char **fmtstring, + struct format_state *state, + struct expression_list *args) +{ + struct format_type ftype; + struct format_type *type; + struct expression *expr; + const char *fmt = *fmtstring; + const char *fmtpost = NULL; + int pos = state->arg_index; + int error = 0; + int ret; + + if (!fmt) { + warning(state->expr->pos, "no format string passed"); + return -1; + } + + /* trivial check for %% */ + fmt++; + if (fmt[0] == '%') { + *fmtstring = fmt+1; + return 0; + } + + state->arg_index++; + state->fmt_index++; + + ret = printf_check_position(&fmt); + if (ret == 0) { + /* we got an invalid position argument */ + error++; + } else if (ret < 0) { + parse_format_printf_checkpos(state, "position"); + } else { + state->used_position = 1; + pos = ret + state->va_start - 1; + } + + /* get rid of any formatting flag bits */ + while (is_printf_flag(*fmt)) + fmt++; + + /* now there is the posibility of a width specifier */ + if (parse_format_printf_argfield(&fmt, state, args, &pos, "width")) + error++; + + /* now we might have the precision specifier */ + if (*fmt == '.') { + fmt++; + if (parse_format_printf_argfield(&fmt, state, args, &pos, "position")) + error++; + } + + type = parse_printf_get_fmt(&ftype, fmt, &fmtpost); + + if (!type && fmt[0] == 'p') + type = &printf_fmt_ptr_ref; /* probably some extension */ + + if (type) { + struct symbol *ctype, *source, *target = NULL; + const char *typediff = "different types"; + int ret; + + *fmtstring = fmtpost; + expr = get_expression_n(args, pos-1); + if (!expr) { + /* no argument, but otherwise valid argument string */ + warning(state->expr->pos, "no argument at position '%d'", pos); + return 0; + } + + ctype = evaluate_expression(expr); + 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; + + 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)); + } + } else { + /* try and find the end of this */ + fmtpost = *fmtstring; + while (*fmtpost > ' ') + fmtpost++; + warning(state->expr->pos, "cannot evaluate type '%.*s'", + (int)(fmtpost - *fmtstring), *fmtstring); + *fmtstring += 1; + return -1; + } + + return 1; +} + +static const char *get_printf_fmt(struct symbol *fn, struct expression_list *head) +{ + struct expression *expr; + const char *fmt_string = NULL; + + expr = get_expression_n(head, fn->ctype.printf_msg-1); + if (!expr) + return NULL; + if (expr->string && expr->string->length) + fmt_string = expr->string->data; + if (!fmt_string) { + struct symbol *sym = evaluate_expression(expr); + + /* attempt to find initialiser for this */ + if (sym && sym->initializer && sym->initializer->string) + 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; + + if (!fmt_string) { + warning(expr->pos, "not a format string?"); + } else { + const char *string = fmt_string; + int fail = 0; + + for (; string[0] != '\0'; string++) { + if (string[0] != '%') + continue; + if (parse_format_printf(&string, &state, head) < 0) + fail++; + string--; + } + + if (fail > 0) + /* format string may have '\n' etc embedded in it */ + warning(expr->pos, "cannot evaluate format string"); + } +} + static int evaluate_arguments(struct symbol *fn, struct expression_list *head) { struct expression *expr; struct symbol_list *argument_types = fn->arguments; + 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 by degenerate() + */ + if (fn->ctype.printf_va_start) + fmt_string = get_printf_fmt(fn, head); + PREPARE_PTR_LIST(argument_types, argtype); FOR_EACH_PTR (head, expr) { struct expression **p = THIS_ADDRESS(expr); @@ -2362,6 +2801,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 (fn->ctype.printf_va_start) + evaluate_format_printf(fmt_string, fn, head); + return 1; } From patchwork Thu Apr 4 18:24:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 10886047 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 57C1715AC for ; Thu, 4 Apr 2019 18:24:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 434D028AC2 for ; Thu, 4 Apr 2019 18:24:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37BE628AD7; Thu, 4 Apr 2019 18:24:09 +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 AB96928AC2 for ; Thu, 4 Apr 2019 18:24:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726698AbfDDSYI (ORCPT ); Thu, 4 Apr 2019 14:24:08 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:59769 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729368AbfDDSYI (ORCPT ); Thu, 4 Apr 2019 14:24:08 -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 1hC71y-0002d5-4K; Thu, 04 Apr 2019 19:24:06 +0100 Received: from ben by rainbowdash.codethink.co.uk with local (Exim 4.92) (envelope-from ) id 1hC71x-0003U2-Qf; Thu, 04 Apr 2019 19:24:05 +0100 From: Ben Dooks To: linux-sparse@vger.kernel.org Cc: Ben Dooks Subject: [RFC v3 3/4] add -Wformat Date: Thu, 4 Apr 2019 19:24:02 +0100 Message-Id: <20190404182403.13192-4-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190404182403.13192-1-ben.dooks@codethink.co.uk> References: <20190404182403.13192-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 Add option to enable/disable format checking (and default it to off) Signed-off-by: Ben Dooks --- Changes since v1: - Default -Wformat off Changes since v2: - Spelling fixes fixup format docs --- evaluate.c | 4 ++-- lib.c | 2 ++ lib.h | 1 + sparse.1 | 9 +++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/evaluate.c b/evaluate.c index d3d9c8e..5081536 100644 --- a/evaluate.c +++ b/evaluate.c @@ -2762,7 +2762,7 @@ static int evaluate_arguments(struct symbol *fn, struct expression_list *head) * do this first, otherwise the arugment info may get lost or changed * later on in the evaluation loop by degenerate() */ - if (fn->ctype.printf_va_start) + if (Wformat && fn->ctype.printf_va_start) fmt_string = get_printf_fmt(fn, head); PREPARE_PTR_LIST(argument_types, argtype); @@ -2802,7 +2802,7 @@ static int evaluate_arguments(struct symbol *fn, struct expression_list *head) } END_FOR_EACH_PTR(expr); FINISH_PTR_LIST(argtype); - if (fn->ctype.printf_va_start) + if (Wformat && fn->ctype.printf_va_start) evaluate_format_printf(fmt_string, fn, head); return 1; diff --git a/lib.c b/lib.c index 83e6a1e..b3bb2e6 100644 --- a/lib.c +++ b/lib.c @@ -269,6 +269,7 @@ int Wimplicit_int = 1; int Winit_cstring = 0; int Wint_to_pointer_cast = 1; int Wenum_mismatch = 1; +int Wformat = 0; int Wsparse_error = 0; int Wmemcpy_max_count = 1; int Wnon_pointer_null = 1; @@ -651,6 +652,7 @@ static const struct flag warnings[] = { { "implicit-int", &Wimplicit_int }, { "init-cstring", &Winit_cstring }, { "int-to-pointer-cast", &Wint_to_pointer_cast }, + { "format", &Wformat }, { "memcpy-max-count", &Wmemcpy_max_count }, { "non-pointer-null", &Wnon_pointer_null }, { "old-initializer", &Wold_initializer }, diff --git a/lib.h b/lib.h index 322408b..c606807 100644 --- a/lib.h +++ b/lib.h @@ -152,6 +152,7 @@ extern int Wdefault_bitfield_sign; extern int Wdesignated_init; extern int Wdo_while; extern int Wenum_mismatch; +extern int Wformat; extern int Wsparse_error; extern int Wimplicit_int; extern int Winit_cstring; diff --git a/sparse.1 b/sparse.1 index 78d0b1e..af9a428 100644 --- a/sparse.1 +++ b/sparse.1 @@ -260,6 +260,15 @@ trouble. Sparse does not issue these warnings by default. . .TP +.B \-Wformat +Warn about parameter mismatch to any variadic function which specifies +where the format string is specified with the +.BI __attribute__((format( type, message, va_start ))) +attribute. + +Sparse does not issue these warnings by default. To turn them on, use +\fB\-Wno\-format\fR +.TP .B \-Wmemcpy\-max\-count Warn about call of \fBmemcpy()\fR, \fBmemset()\fR, \fBcopy_from_user()\fR, or \fBcopy_to_user()\fR with a large compile-time byte count. From patchwork Thu Apr 4 18:24:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 10886051 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 8253D13B5 for ; Thu, 4 Apr 2019 18:24:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BE6828AC2 for ; Thu, 4 Apr 2019 18:24:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 602A128ADA; Thu, 4 Apr 2019 18:24:10 +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 316B828AD3 for ; Thu, 4 Apr 2019 18:24:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729368AbfDDSYJ (ORCPT ); Thu, 4 Apr 2019 14:24:09 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:59771 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729526AbfDDSYI (ORCPT ); Thu, 4 Apr 2019 14:24:08 -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 1hC71y-0002d6-5m; Thu, 04 Apr 2019 19:24:06 +0100 Received: from ben by rainbowdash.codethink.co.uk with local (Exim 4.92) (envelope-from ) id 1hC71x-0003U5-Rt; Thu, 04 Apr 2019 19:24:05 +0100 From: Ben Dooks To: linux-sparse@vger.kernel.org Cc: Ben Dooks Subject: [RFC v3 4/4] tests: add varargs printf format tests Date: Thu, 4 Apr 2019 19:24:03 +0100 Message-Id: <20190404182403.13192-5-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190404182403.13192-1-ben.dooks@codethink.co.uk> References: <20190404182403.13192-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 Add some tests for the new printf format checking code. Note, these do not all pass yet. Signed-off-by: Ben Dooks --- validation/varargs-format-addrspace1.c | 36 ++++++++ validation/varargs-format-bad.c | 18 ++++ validation/varargs-format-checking.c | 20 +++++ validation/varargs-format-position.c | 31 +++++++ validation/varargs-format-prefix.c | 19 ++++ validation/varargs-format-tests.c | 37 ++++++++ validation/varargs-type-formattest.c | 116 +++++++++++++++++++++++++ 7 files changed, 277 insertions(+) create mode 100644 validation/varargs-format-addrspace1.c create mode 100644 validation/varargs-format-bad.c create mode 100644 validation/varargs-format-checking.c create mode 100644 validation/varargs-format-position.c create mode 100644 validation/varargs-format-prefix.c create mode 100644 validation/varargs-format-tests.c create mode 100644 validation/varargs-type-formattest.c diff --git a/validation/varargs-format-addrspace1.c b/validation/varargs-format-addrspace1.c new file mode 100644 index 0000000..d431940 --- /dev/null +++ b/validation/varargs-format-addrspace1.c @@ -0,0 +1,36 @@ + +extern int variadic(char *msg, ...) __attribute__((format (printf, 1, 2))); +extern int variadic2(char *msg, int , ...) __attribute__((format (printf, 1, 3))); +extern int variadic3(int, char *msg, ...) __attribute__((format (printf, 2, 3))); + +static void test(void) { + void __attribute__((noderef, address_space(1))) *a; + void *b; + + variadic("%s\n", a); + variadic("%s\n", b); + variadic("%s %s\n", b, a); + variadic2("%s %s\n", 1, b, a); + variadic3(1, "%s %s\n", b, a); + variadic3(1, "%s %p\n", b, a); +} + +/* + * check-name: variadic formatting test with address-space to %s + * check-command: sparse -Wformat $file + * + * check-error-start +varargs-format-addrspace1.c:10:26: warning: incorrect type in argument 2 (different address spaces) +varargs-format-addrspace1.c:10:26: expected char * +varargs-format-addrspace1.c:10:26: got void [noderef] *a +varargs-format-addrspace1.c:12:32: warning: incorrect type in argument 3 (different address spaces) +varargs-format-addrspace1.c:12:32: expected char * +varargs-format-addrspace1.c:12:32: got void [noderef] *a +varargs-format-addrspace1.c:13:36: warning: incorrect type in argument 4 (different address spaces) +varargs-format-addrspace1.c:13:36: expected char * +varargs-format-addrspace1.c:13:36: got void [noderef] *a +varargs-format-addrspace1.c:14:36: warning: incorrect type in argument 4 (different address spaces) +varargs-format-addrspace1.c:14:36: expected char * +varargs-format-addrspace1.c:14:36: got void [noderef] *a + * check-error-end + */ diff --git a/validation/varargs-format-bad.c b/validation/varargs-format-bad.c new file mode 100644 index 0000000..82ae357 --- /dev/null +++ b/validation/varargs-format-bad.c @@ -0,0 +1,18 @@ + +extern int variadic(char *msg, ...) __attribute__((format (printf, 0, 0))); +extern int variadic2(char *msg, int , ...) __attribute__((format (printf, 2, 2))); +extern int variadic3(char *msg, int , ...) __attribute__((format (printf, 2, 1))); + +static void test(void) { +} + +/* + * check-name: variadic formatting test with bad formatting parameters + * check-command: sparse -Wformat $file + * + * check-error-start +varargs-format-bad.c:2:73: warning: bad format positions +varargs-format-bad.c:3:80: warning: bad format positions +varargs-format-bad.c:4:80: warning: format cannot be after va_args +* check-error-end + */ diff --git a/validation/varargs-format-checking.c b/validation/varargs-format-checking.c new file mode 100644 index 0000000..4444800 --- /dev/null +++ b/validation/varargs-format-checking.c @@ -0,0 +1,20 @@ + +extern void pf(char *msg, ...) __attribute__((format (printf, 1, 2))); + +static void test(void) { + pf("%u %lu %llu\n", 1U, 1UL, 1ULL); + pf("%d %ld %lld\n", 1, 1L, 1LL); + pf("%x %lx %llx\n", 1U, 1UL, 1ULL); + pf("%d %ld %lld\n", 1, 1L, 1L); +} + +/* + * check-name: variadic formatting test type checking + * check-command: sparse -Wformat $file + * + * check-error-start +varargs-format-checking.c:8:36: warning: incorrect type in argument 4 (different types) +varargs-format-checking.c:8:36: expected long long +varargs-format-checking.c:8:36: got long + * check-error-end + */ diff --git a/validation/varargs-format-position.c b/validation/varargs-format-position.c new file mode 100644 index 0000000..cb57f64 --- /dev/null +++ b/validation/varargs-format-position.c @@ -0,0 +1,31 @@ + +extern void pf(char *msg, ...) __attribute__((format (printf, 1, 2))); + +static void test(void) { + pf("%2$d %u\n", 1U, 1L); + pf("%3$d %2$u\n", 1U, 1); + pf("%1$d %2$d\n", 1L, 1); +} + +/* + * check-name: variadic formatting test position checking + * check-command: sparse -Wformat $file + * + * check-error-start +varargs-format-position.c:5:29: warning: incorrect type in argument 3 (different types) +varargs-format-position.c:5:29: expected int +varargs-format-position.c:5:29: got long +varargs-format-position.c:5:12: warning: format 3: position: no position specified +varargs-format-position.c:5:29: warning: incorrect type in argument 3 (different types) +varargs-format-position.c:5:29: expected unsigned int +varargs-format-position.c:5:29: got long +varargs-format-position.c:6:12: warning: no argument at position '4' +varargs-format-position.c:6:31: warning: incorrect type in argument 3 (different types) +varargs-format-position.c:6:31: expected unsigned int +varargs-format-position.c:6:31: got int +varargs-format-position.c:7:27: warning: incorrect type in argument 2 (different types) +varargs-format-position.c:7:27: expected int +varargs-format-position.c:7:27: got long + * check-error-end + * + */ diff --git a/validation/varargs-format-prefix.c b/validation/varargs-format-prefix.c new file mode 100644 index 0000000..ff0f0b8 --- /dev/null +++ b/validation/varargs-format-prefix.c @@ -0,0 +1,19 @@ + +extern int __attribute__((format (printf, 1, 2))) variadic(char *msg, ...); + +static int test(void) { + void __attribute__((noderef, address_space(1))) *a; + + variadic("%s\n", a); +} + +/* + * check-name: variadic formatting test prefix based __attribute__ + * check-command: sparse -Wformat $file + * + * check-error-start +varargs-format-prefix.c:7:26: warning: incorrect type in argument 2 (different address spaces) +varargs-format-prefix.c:7:26: expected char * +varargs-format-prefix.c:7:26: got void [noderef] *a + * check-error-end + */ diff --git a/validation/varargs-format-tests.c b/validation/varargs-format-tests.c new file mode 100644 index 0000000..3154ec1 --- /dev/null +++ b/validation/varargs-format-tests.c @@ -0,0 +1,37 @@ + +extern void pf(char *msg, ...) __attribute__((format (printf, 1, 2))); + +static int test(void) +{ + pf("%*d\n", 5, 10); /* value 10, print width is 5 */ + pf("%2$*1$d\n", 5, 10); /* value 10, print width is 5 */ + pf("%3$*2$d\n", 1, 5, 10); /* ok, skipping the '1' */ + pf("%3$-*2$d\n", 1, 5, 10); /* ok, skipping the '1' */ + pf("%3$*2$-d\n", 1, 5, 10); /* bad, the "-" shouldn't be before the 'd' */ + pf("%3$ *2$d\n", 1, 5, 10); /* ok, skipping the '1' */ + pf("%3$+*2$d\n", 1, 5, 10); /* ok, skipping the '1' */ + pf("%3$0+*2$d\n", 1, 5, 10); /* ok, skipping the '1' */ + pf("%3$+0*2$d\n", 1, 5, 10); /* ok, skipping the '1' */ + pf("%3$+#*2$d\n", 1, 5, 10); /* ok, skipping the '1' */ + pf("%3$+#*2$.5d\n", 1, 5, 10); /* ok, skipping the '1' */ + + /* go with some precision as well as width strings */ + pf("%2$+*1$.6d\n", 5, 10); /* ok */ + pf("%2$+*1$.*3$d\n", 5, 10, 6); /* ok */ + pf("%2$+*3$.*1$d\n", 6, 10, 5); /* ok */ + pf("%2$+*1$.*d\n", 5, 10, 6); /* not ok */ + + pf("%s", "msg"); + return 0; +} + +/* + * check-name: variadic formatting tests for width/precisions + * check-command: sparse -Wformat $file + * + * check-error-start +varargs-format-tests.c:10:12: warning: cannot evaluate type '%3$*2$-d' +varargs-format-tests.c:10:12: warning: cannot evaluate format string +varargs-format-tests.c:22:12: warning: format 3: position: no position specified + * check-error-end + */ diff --git a/validation/varargs-type-formattest.c b/validation/varargs-type-formattest.c new file mode 100644 index 0000000..03a897a --- /dev/null +++ b/validation/varargs-type-formattest.c @@ -0,0 +1,116 @@ + +extern void pf1(char *msg, ...) __attribute__((format (printf, 1, 2))); +extern void pf2(int m, char *msg, ...) __attribute__((format (printf, 2, 3))); + +/* run all the tests with both of these printf formatted types */ +#define pf(x...) do { pf1(x); pf2(1, x); } while(0); + +static void test(void) { + /* first two are valid */ + pf("%*d", 5, 10); /* value 10, print width is 5 */ + pf("%2$*1$d", 5, 10); /* value 10, print width is 5 */ + pf("%2$*3$d", 5, 10); /* value 10, print width is ?? */ + + pf("%*d", 5, 10); /* value 10, print width is 5 */ + pf("%*d", 5, 10L); /* value 10, print width is 5 (bad type) */ + pf("%*d", 5UL, 10L); /* value 10, print width is 5 (bad type) */ + + pf("%3$*2$d", 1, 5, 10); /* ok, skipping the '1' */ + pf("%3$*2$d", 1, 5, 10L); /* bad print type */ + pf("%2$*3$d", 1UL, 10, 5); /* ok, try with swapping width/val */ + pf("%2$*3$d", 1UL, 10L, 5); /* bad, try with swapping width/val */ + + /* and now try with precision specifiers */ + + pf("%*.6d", 5, 10); /* value 10, print width is 5 */ + pf("%*.6d", 5, 10L); /* value 10, print width is 5 (bad type) */ + pf("%*.6d", 5UL, 10L); /* value 10, print width is 5 (bad type) */ + + pf("%*.*d", 5, 6, 10); /* value 10, print width is 5 */ + pf("%*.*d", 5, 6, 10L); /* value 10, print width is 5 (bad type) */ + pf("%*.*d", 5UL, 6, 10L); /* value 10, print width is 5 (bad type) */ + pf("%*.*d", 5, 6UL, 10); /* value 10, print width is 5 (bad type) */ +} + +/* + * check-name: variadic formatting test position checking types + * check-command: sparse -Wformat $file + * + * check-error-start +varargs-type-formattest.c:12:9: warning: width: no argument at position 4 +varargs-type-formattest.c:12:9: warning: width: no argument at position 5 +varargs-type-formattest.c:15:9: warning: incorrect type in argument 3 (different types) +varargs-type-formattest.c:15:9: expected int +varargs-type-formattest.c:15:9: got long +varargs-type-formattest.c:15:9: warning: incorrect type in argument 4 (different types) +varargs-type-formattest.c:15:9: expected int +varargs-type-formattest.c:15:9: got long +varargs-type-formattest.c:16:9: warning: incorrect type for width argument 2 +varargs-type-formattest.c:16:9: expected int +varargs-type-formattest.c:16:9: got unsigned long +varargs-type-formattest.c:16:9: warning: incorrect type in argument 3 (different types) +varargs-type-formattest.c:16:9: expected int +varargs-type-formattest.c:16:9: got long +varargs-type-formattest.c:16:9: warning: incorrect type for width argument 3 +varargs-type-formattest.c:16:9: expected int +varargs-type-formattest.c:16:9: got unsigned long +varargs-type-formattest.c:16:9: warning: incorrect type in argument 4 (different types) +varargs-type-formattest.c:16:9: expected int +varargs-type-formattest.c:16:9: got long +varargs-type-formattest.c:19:9: warning: incorrect type in argument 4 (different types) +varargs-type-formattest.c:19:9: expected int +varargs-type-formattest.c:19:9: got long +varargs-type-formattest.c:19:9: warning: incorrect type in argument 5 (different types) +varargs-type-formattest.c:19:9: expected int +varargs-type-formattest.c:19:9: got long +varargs-type-formattest.c:21:9: warning: incorrect type in argument 3 (different types) +varargs-type-formattest.c:21:9: expected int +varargs-type-formattest.c:21:9: got long +varargs-type-formattest.c:21:9: warning: incorrect type in argument 4 (different types) +varargs-type-formattest.c:21:9: expected int +varargs-type-formattest.c:21:9: got long +varargs-type-formattest.c:26:9: warning: incorrect type in argument 3 (different types) +varargs-type-formattest.c:26:9: expected int +varargs-type-formattest.c:26:9: got long +varargs-type-formattest.c:26:9: warning: incorrect type in argument 4 (different types) +varargs-type-formattest.c:26:9: expected int +varargs-type-formattest.c:26:9: got long +varargs-type-formattest.c:27:9: warning: incorrect type for width argument 2 +varargs-type-formattest.c:27:9: expected int +varargs-type-formattest.c:27:9: got unsigned long +varargs-type-formattest.c:27:9: warning: incorrect type in argument 3 (different types) +varargs-type-formattest.c:27:9: expected int +varargs-type-formattest.c:27:9: got long +varargs-type-formattest.c:27:9: warning: incorrect type for width argument 3 +varargs-type-formattest.c:27:9: expected int +varargs-type-formattest.c:27:9: got unsigned long +varargs-type-formattest.c:27:9: warning: incorrect type in argument 4 (different types) +varargs-type-formattest.c:27:9: expected int +varargs-type-formattest.c:27:9: got long +varargs-type-formattest.c:30:9: warning: incorrect type in argument 4 (different types) +varargs-type-formattest.c:30:9: expected int +varargs-type-formattest.c:30:9: got long +varargs-type-formattest.c:30:9: warning: incorrect type in argument 5 (different types) +varargs-type-formattest.c:30:9: expected int +varargs-type-formattest.c:30:9: got long +varargs-type-formattest.c:31:9: warning: incorrect type for width argument 2 +varargs-type-formattest.c:31:9: expected int +varargs-type-formattest.c:31:9: got unsigned long +varargs-type-formattest.c:31:9: warning: incorrect type in argument 4 (different types) +varargs-type-formattest.c:31:9: expected int +varargs-type-formattest.c:31:9: got long +varargs-type-formattest.c:31:9: warning: incorrect type for width argument 3 +varargs-type-formattest.c:31:9: expected int +varargs-type-formattest.c:31:9: got unsigned long +varargs-type-formattest.c:31:9: warning: incorrect type in argument 5 (different types) +varargs-type-formattest.c:31:9: expected int +varargs-type-formattest.c:31:9: got long +varargs-type-formattest.c:32:9: warning: incorrect type for position argument 3 +varargs-type-formattest.c:32:9: expected int +varargs-type-formattest.c:32:9: got unsigned long +varargs-type-formattest.c:32:9: warning: incorrect type for position argument 4 +varargs-type-formattest.c:32:9: expected int +varargs-type-formattest.c:32:9: got unsigned long + * check-error-end + * + */