Introduce a syslog format that accepts %m. Stop accepting %m in printf

like formats. Support for this is detected via the __syslog_attribute__
macro.
This commit is contained in:
christos 2015-10-14 16:05:14 +00:00
parent 55b72e0a94
commit d8e986fab6
6 changed files with 42 additions and 6 deletions

View File

@ -860,14 +860,20 @@ static const format_kind_info format_types_orig[] =
},
{ "gnu_strftime", NULL, time_char_table, "_-0^#", "EO",
strftime_flag_specs, strftime_flag_pairs,
FMT_FLAG_FANCY_PERCENT_OK, 'w', 0, 0, 0, 0, 0,
FMT_FLAG_FANCY_PERCENT_OK|FMT_FLAG_M_OK, 'w', 0, 0, 0, 0, 0,
NULL, NULL
},
{ "gnu_strfmon", strfmon_length_specs, monetary_char_table, "=^+(!-", NULL,
strfmon_flag_specs, strfmon_flag_pairs,
FMT_FLAG_ARG_CONVERT, 'w', '#', 'p', 0, 'L', 0,
NULL, NULL
}
},
{ "gnu_syslog", 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|FMT_FLAG_M_OK,
'w', 0, 'p', 0, 'L', 0,
&integer_type_node, &integer_type_node
},
};
/* This layer of indirection allows GCC to reassign format_types with
@ -1983,6 +1989,14 @@ check_format_info_main (format_check_results *res,
warning (OPT_Wformat_, "conversion lacks type at end of format");
continue;
}
if (format_char == 'm' && !(fki->flags & FMT_FLAG_M_OK))
{
warning (OPT_Wformat_,
"%%m is only allowed in syslog(3) like functions");
continue;
}
format_chars++;
fci = fki->conversion_specs;
while (fci->format_chars != 0
@ -2854,6 +2868,7 @@ extern const target_ovr_attr TARGET_OVERRIDES_FORMAT_ATTRIBUTES[];
static const target_ovr_attr gnu_target_overrides_format_attributes[] =
{
{ "gnu_printf", "printf" },
{ "gnu_syslog", "syslog" },
{ "gnu_scanf", "scanf" },
{ "gnu_strftime", "strftime" },
{ "gnu_strfmon", "strfmon" },

View File

@ -75,11 +75,13 @@ enum
FMT_FLAG_DOLLAR_GAP_POINTER_OK = 128,
/* The format arg is an opaque object that will be parsed by an external
facility. */
FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL = 256
FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL = 256,
/* Not included here: details of whether width or precision may occur
(controlled by width_char and precision_char); details of whether
'*' can be used for these (width_type and precision_type); details
of whether length modifiers can occur (length_char_specs). */
FMT_FLAG_M_OK = 512
/* %m is only allowed in syslog */
};
/* Structure describing a length modifier supported in format checking, and

View File

@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see
{ \
builtin_define ("__NetBSD__"); \
builtin_define ("__unix__"); \
builtin_define ("__syslog_attribute__"); \
builtin_assert ("system=bsd"); \
builtin_assert ("system=unix"); \
builtin_assert ("system=NetBSD"); \

View File

@ -860,14 +860,20 @@ static const format_kind_info format_types_orig[] =
},
{ "gnu_strftime", NULL, time_char_table, "_-0^#", "EO",
strftime_flag_specs, strftime_flag_pairs,
FMT_FLAG_FANCY_PERCENT_OK, 'w', 0, 0, 0, 0, 0,
FMT_FLAG_FANCY_PERCENT_OK|FMT_FLAG_M_OK, 'w', 0, 0, 0, 0, 0,
NULL, NULL
},
{ "gnu_strfmon", strfmon_length_specs, monetary_char_table, "=^+(!-", NULL,
strfmon_flag_specs, strfmon_flag_pairs,
FMT_FLAG_ARG_CONVERT, 'w', '#', 'p', 0, 'L', 0,
NULL, NULL
}
},
{ "gnu_syslog", 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|FMT_FLAG_M_OK,
'w', 0, 'p', 0, 'L', 0,
&integer_type_node, &integer_type_node
},
};
/* This layer of indirection allows GCC to reassign format_types with
@ -1983,6 +1989,14 @@ check_format_info_main (format_check_results *res,
warning (OPT_Wformat_, "conversion lacks type at end of format");
continue;
}
if (format_char == 'm' && !(fki->flags & FMT_FLAG_M_OK))
{
warning (OPT_Wformat_,
"%%m is only allowed in syslog(3) like functions");
continue;
}
format_chars++;
fci = fki->conversion_specs;
while (fci->format_chars != 0
@ -2854,6 +2868,7 @@ extern const target_ovr_attr TARGET_OVERRIDES_FORMAT_ATTRIBUTES[];
static const target_ovr_attr gnu_target_overrides_format_attributes[] =
{
{ "gnu_printf", "printf" },
{ "gnu_syslog", "syslog" },
{ "gnu_scanf", "scanf" },
{ "gnu_strftime", "strftime" },
{ "gnu_strfmon", "strfmon" },

View File

@ -75,11 +75,13 @@ enum
FMT_FLAG_DOLLAR_GAP_POINTER_OK = 128,
/* The format arg is an opaque object that will be parsed by an external
facility. */
FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL = 256
FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL = 256,
/* Not included here: details of whether width or precision may occur
(controlled by width_char and precision_char); details of whether
'*' can be used for these (width_type and precision_type); details
of whether length modifiers can occur (length_char_specs). */
FMT_FLAG_M_OK = 512
/* %m is only allowed in syslog */
};
/* Structure describing a length modifier supported in format checking, and

View File

@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see
{ \
builtin_define ("__NetBSD__"); \
builtin_define ("__unix__"); \
builtin_define ("__syslog_attribute__"); \
builtin_assert ("system=bsd"); \
builtin_assert ("system=unix"); \
builtin_assert ("system=NetBSD"); \