This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix for printf format checking
- To: egcs-patches at cygnus dot com
- Subject: Fix for printf format checking
- From: Andreas Schwab <schwab at issan dot informatik dot uni-dortmund dot de>
- Date: 02 Jun 1998 11:22:48 +0200
- Cc: schwab at issan dot informatik dot uni-dortmund dot de
It seems like someone has thrown out the check for the `hh' length
modifier in check_format_info while merging in other changes, or whatever.
I have also extended it to check for %n writing into a const type.
1998-05-31 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* c-common.c (check_format_info): Put back check for C9x `hh'
length modifier. Warn about %n format writing into const. Remove
obsolete comment.
(format_char_info): Fix comments.
--- egcs-2.91.33/gcc/c-common.c.~1~ Thu May 28 12:23:13 1998
+++ egcs-2.91.33/gcc/c-common.c Sun May 31 10:37:02 1998
@@ -979,10 +979,10 @@
int pointer_count;
/* Type of argument if no length modifier is used. */
tree *nolen;
- /* Type of argument if length modifier for shortening is used.
+ /* Type of argument if length modifier for shortening to byte is used.
If NULL, then this modifier is not allowed. */
tree *hhlen;
- /* Type of argument if length modifier for shortening to byte if used.
+ /* Type of argument if length modifier for shortening is used.
If NULL, then this modifier is not allowed. */
tree *hlen;
/* Type of argument if length modifier `l' is used.
@@ -1556,6 +1556,13 @@
if (pedantic)
warning ("ANSI C does not support the `ll' length modifier");
}
+ else if (length_char == 'h' && *format_chars == 'h')
+ {
+ length_char = 'H', format_chars++;
+ /* FIXME: Is allowed in ISO C 9x. */
+ if (pedantic)
+ warning ("ANSI C does not support the `hh' length modifier");
+ }
if (*format_chars == 'a' && info->format_type == scanf_format_type)
{
if (format_chars[1] == 's' || format_chars[1] == 'S'
@@ -1688,15 +1695,6 @@
warning ("use of `%c' length character with `%c' type character",
length_char, format_char);
- /*
- ** XXX -- should kvetch about stuff such as
- ** {
- ** const int i;
- **
- ** scanf ("%d", &i);
- ** }
- */
-
/* Finally. . .check type of argument against desired type! */
if (info->first_arg_num == 0)
continue;
@@ -1739,8 +1737,10 @@
}
/* See if this is an attempt to write into a const type with
- scanf. */
- if (info->format_type == scanf_format_type
+ scanf or with printf "%n". */
+ if ((info->format_type == scanf_format_type
+ || (info->format_type == printf_format_type
+ && format_char == 'n'))
&& i == fci->pointer_count + aflag
&& wanted_type != 0
&& TREE_CODE (cur_type) != ERROR_MARK
--
Andreas Schwab "And now for something
schwab@issan.informatik.uni-dortmund.de completely different"
schwab@gnu.org