From f9f9640f8464328726ca641a942366145504a7bd Mon Sep 17 00:00:00 2001 From: Danny Smith Date: Thu, 24 Apr 2008 07:42:07 +0000 Subject: [PATCH] c-format.c (check_format_info_main): Use strncmp rather than a magic prefix to handle multichar length specs. gcc * c-format.c (check_format_info_main): Use strncmp rather than a magic prefix to handle multichar length specs. * config/i386/msformat-c.c (format_length_info ms_printf_length_specs): Don't prefix "I64" and "I32" with '\0'. testsuite * gcc.dg/format/ms-warnI64-1.c: New file. From-SVN: r134623 --- gcc/ChangeLog | 7 ++++++ gcc/c-format.c | 20 +++------------- gcc/config/i386/msformat-c.c | 4 ++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/format/ms-warnI64-1.c | 28 ++++++++++++++++++++++ 5 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/format/ms-warnI64-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 08b6230876b..1c9599e547a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2008-04-24 Danny Smith + + * c-format.c (check_format_info_main): Use strncmp rather than a magic prefix + to handle multichar length specs. + * config/i386/msformat-c.c (format_length_info ms_printf_length_specs): + Don't prefix "I64" and "I32" with '\0'. + 2008-04-24 Jakub Jelinek PR target/36015 diff --git a/gcc/c-format.c b/gcc/c-format.c index d1a136f87ec..82f5ff39bc9 100644 --- a/gcc/c-format.c +++ b/gcc/c-format.c @@ -1779,26 +1779,12 @@ check_format_info_main (format_check_results *res, length_chars_std = STD_C89; if (fli) { - while (fli->name != 0 && fli->name[0] != *format_chars) - { - if (fli->name[0] == '\0') - { - int si = strlen (fli->name + 1) + 1; - int i = 1; - while (fli->name[i] != 0 && fli->name[i] == format_chars [i - 1]) - ++i; - if (si == i) - { - if (si > 2) - format_chars += si - 2; - break; - } - } + while (fli->name != 0 + && strncmp (fli->name, format_chars, strlen (fli->name))) fli++; - } if (fli->name != 0) { - format_chars++; + format_chars += strlen (fli->name); if (fli->double_name != 0 && fli->name[0] == *format_chars) { format_chars++; diff --git a/gcc/config/i386/msformat-c.c b/gcc/config/i386/msformat-c.c index 821be470b8e..90365557a69 100644 --- a/gcc/config/i386/msformat-c.c +++ b/gcc/config/i386/msformat-c.c @@ -38,8 +38,8 @@ static const format_length_info ms_printf_length_specs[] = { { "h", FMT_LEN_h, STD_C89, NULL, 0, 0 }, { "l", FMT_LEN_l, STD_C89, NULL, 0, 0 }, - { "\0I32", FMT_LEN_l, STD_EXT, NULL, 0, 0 }, - { "\0I64", FMT_LEN_ll, STD_EXT, NULL, 0, 0 }, + { "I32", FMT_LEN_l, STD_EXT, NULL, 0, 0 }, + { "I64", FMT_LEN_ll, STD_EXT, NULL, 0, 0 }, { "I", FMT_LEN_L, STD_EXT, NULL, 0, 0 }, { NULL, 0, 0, NULL, 0, 0 } }; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2332f6908f9..b533b938dc8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2008-04-24 Danny Smith + + * gcc.dg/format/ms-warnI64-1.c: New file. + 2008-04-24 Jakub Jelinek PR target/36015 diff --git a/gcc/testsuite/gcc.dg/format/ms-warnI64-1.c b/gcc/testsuite/gcc.dg/format/ms-warnI64-1.c new file mode 100644 index 00000000000..b5d31d2fe50 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/ms-warnI64-1.c @@ -0,0 +1,28 @@ +/* Test for printf formats. Test for ISO C warnings with MS "I64" + extension.*/ + +/* { dg-do compile { target { *-*-mingw* } } } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat -Wno-long-long" } */ + +#define USE_SYSTEM_FORMATS +#include "format.h" + +void +foo (long long ll, unsigned long long ull, long long *lln, + long long *llp, unsigned long long *ullp) +{ + printf ("%I64d", ll); /* { dg-warning "'I64' ms_printf length modifier" "printf %I64d" } */ + printf ("%I64i", ll); /* { dg-warning "'I64' ms_printf length modifier" "printf %I64i" } */ + printf ("%I64o", ull); /* { dg-warning "'I64' ms_printf length modifier" "printf %I64o" } */ + printf ("%I64u", ull); /* { dg-warning "'I64' ms_printf length modifier" "printf %I64u" } */ + printf ("%I64x", ull); /* { dg-warning "'I64' ms_printf length modifier" "printf %I64x" } */ + printf ("%I64X", ull); /* { dg-warning "'I64' ms_printf length modifier" "printf %I64X" } */ + printf ("%I64n", lln); /* { dg-warning "'I64' ms_printf length modifier" "printf %I64n" } */ + scanf ("%I64d", llp); /* { dg-warning "'I64' ms_scanf length modifier" "scanf %I64d" } */ + scanf ("%I64i", llp); /* { dg-warning "'I64' ms_scanf length modifier" "scanf %I64i" } */ + scanf ("%I64o", ullp); /* { dg-warning "'I64' ms_scanf length modifier" "scanf %I64o" } */ + scanf ("%I64u", ullp); /* { dg-warning "'I64' ms_scanf length modifier" "scanf %I64u" } */ + scanf ("%I64x", ullp); /* { dg-warning "'I64' ms_scanf length modifier" "scanf %I64x" } */ + scanf ("%I64X", ullp); /* { dg-warning "'I64' ms_scanf length modifier" "scanf %I64X" } */ + scanf ("%I64n", llp); /* { dg-warning "'I64' ms_scanf length modifier" "scanf %I64n" } */ +} -- 2.30.2