summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/c-format.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/gcc/c-format.c')
-rw-r--r--contrib/gcc/c-format.c94
1 files changed, 88 insertions, 6 deletions
diff --git a/contrib/gcc/c-format.c b/contrib/gcc/c-format.c
index 083e912..5c8cdf7 100644
--- a/contrib/gcc/c-format.c
+++ b/contrib/gcc/c-format.c
@@ -19,6 +19,8 @@ along with GCC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
+/* $FreeBSD$ */
+
#include "config.h"
#include "system.h"
#include "tree.h"
@@ -56,6 +58,7 @@ set_Wformat (setting)
last. */
enum format_type { printf_format_type, scanf_format_type,
strftime_format_type, strfmon_format_type,
+ printf0_format_type,
format_type_error };
typedef struct function_format_info
@@ -230,7 +233,7 @@ decode_format_attr (args, info, validated_p)
{
if (validated_p)
abort ();
- error ("unrecognized format specifier");
+ error_with_decl (getdecls (), "unrecognized format specifier");
return false;
}
else
@@ -521,6 +524,7 @@ typedef struct
/* Pointer to type of argument expected if '*' is used for a precision,
or NULL if '*' not used for precisions. */
tree *const precision_type;
+ const int null_format_ok;
} format_kind_info;
@@ -762,6 +766,18 @@ static const format_char_info print_char_table[] =
{ "S", 1, STD_EXT, { TEX_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "R" },
/* GNU conversion specifiers. */
{ "m", 0, STD_EXT, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "" },
+ /* BSD conversion specifiers. */
+ /* FreeBSD kernel extensions (src/sys/kern/subr_prf.c).
+ The format %b is supported to decode error registers.
+ Its usage is: printf("reg=%b\n", regval, "<base><arg>*");
+ which produces: reg=3<BITTWO,BITONE>
+ The format %D provides a hexdump given a pointer and separator string:
+ ("%6D", ptr, ":") -> XX:XX:XX:XX:XX:XX
+ ("%*D", len, ptr, " ") -> XX XX XX XX ...
+ */
+ { "D", 1, STD_EXT, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "cR" },
+ { "b", 1, STD_EXT, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "" },
+ { "ry", 0, STD_EXT, { T89_I, BADLEN, BADLEN, T89_L, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +#", "i" },
{ NULL, 0, 0, NOLENGTHS, NULL, NULL }
};
@@ -826,23 +842,29 @@ static const format_kind_info format_types[] =
printf_flag_specs, printf_flag_pairs,
FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK,
'w', 0, 'p', 0, 'L',
- &integer_type_node, &integer_type_node
+ &integer_type_node, &integer_type_node, 0
},
{ "scanf", scanf_length_specs, scan_char_table, "*'I", NULL,
scanf_flag_specs, scanf_flag_pairs,
FMT_FLAG_ARG_CONVERT|FMT_FLAG_SCANF_A_KLUDGE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_ZERO_WIDTH_BAD|FMT_FLAG_DOLLAR_GAP_POINTER_OK,
'w', 0, 0, '*', 'L',
- NULL, NULL
+ NULL, NULL, 0
},
{ "strftime", NULL, time_char_table, "_-0^#", "EO",
strftime_flag_specs, strftime_flag_pairs,
FMT_FLAG_FANCY_PERCENT_OK, 'w', 0, 0, 0, 0,
- NULL, NULL
+ NULL, NULL, 0
},
{ "strfmon", strfmon_length_specs, monetary_char_table, "=^+(!-", NULL,
strfmon_flag_specs, strfmon_flag_pairs,
FMT_FLAG_ARG_CONVERT, 'w', '#', 'p', 0, 'L',
- NULL, NULL
+ NULL, NULL, 0
+ },
+ { "printf0", printf_length_specs, print_char_table, " +#0-'I", NULL,
+ printf_flag_specs, printf_flag_pairs,
+ FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK,
+ 'w', 0, 'p', 0, 'L',
+ &integer_type_node, &integer_type_node, 1
}
};
@@ -1389,6 +1411,15 @@ check_format_arg (ctx, format_tree, arg_num)
if (integer_zerop (format_tree))
{
+ /* FIXME: this warning should go away once Marc Espie's
+ __attribute__((nonnull)) patch is in. Instead, checking for
+ nonnull attributes should probably change this function to act
+ specially if info == NULL and add a res->number_null entry for
+ that case, or maybe add a function pointer to be called at
+ the end instead of hardcoding check_format_info_main. */
+ if (!format_types[info->format_type].null_format_ok)
+ status_warning (status, "null format string");
+
/* Skip to first argument to check, so we can see if this format
has any arguments (it shouldn't). */
while (arg_num + 1 < info->first_arg_num)
@@ -1898,6 +1929,57 @@ check_format_info_main (status, res, info, format_chars, format_length,
}
}
+ if (*format_chars == 'b')
+ {
+ /* There should be an int arg to control the string arg. */
+ if (params == 0)
+ {
+ status_warning (status, "too few arguments for format");
+ return;
+ }
+ if (info->first_arg_num != 0)
+ {
+ cur_param = TREE_VALUE (params);
+ params = TREE_CHAIN (params);
+ ++arg_num;
+ if ((TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
+ != integer_type_node)
+ &&
+ (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
+ != unsigned_type_node))
+ {
+ status_warning (status, "bitmap is not type int (arg %d)",
+ arg_num);
+ }
+ }
+ }
+ if (*format_chars == 'D')
+ {
+ /* There should be an unsigned char * arg before the string arg. */
+ if (params == 0)
+ {
+ status_warning (status, "too few arguments for format");
+ return;
+ }
+ if (info->first_arg_num != 0)
+ {
+ tree cur_type;
+
+ cur_param = TREE_VALUE (params);
+ params = TREE_CHAIN (params);
+ ++arg_num;
+ cur_type = TREE_TYPE (cur_param);
+ if (TREE_CODE (cur_type) != POINTER_TYPE
+ || TYPE_MAIN_VARIANT (TREE_TYPE (cur_type))
+ != unsigned_char_type_node)
+ {
+ status_warning (status,
+ "ethernet address is not type unsigned char * (arg %d)",
+ arg_num);
+ }
+ }
+ }
+
format_char = *format_chars;
if (format_char == 0
|| (!(fki->flags & (int) FMT_FLAG_FANCY_PERCENT_OK)
@@ -2024,7 +2106,7 @@ check_format_info_main (status, res, info, format_chars, format_length,
else if (strchr (fci->flags2, '2') != 0)
y2k_level = 2;
if (y2k_level == 3)
- status_warning (status, "`%%%c' yields only last 2 digits of year in some locales",
+ status_warning (status, "`%%%c' yields only last 2 digits of year in some locales on non-BSD systems",
format_char);
else if (y2k_level == 2)
status_warning (status, "`%%%c' yields only last 2 digits of year", format_char);
OpenPOWER on IntegriCloud