mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-16 07:43:03 +00:00
maint: port to strict C function type checking
Violation of C standard detected by clang -fsanitize=undefined with clang 19.1.7 on Fedora 41 x86-64. * src/counterexample.c (si_bfs_free): * src/files.c (prefix_map_free, add_prefix_map): * src/fixits.c (fixit_cmp, fixit_free, fixits_register): (expand_to_conflict, nonunifying_shift_path) (search_state_free_children, search_state_free, ssb_free) (ssb_hasher, ssb_comp, ssb_equals, visited_hasher) (visited_comparator, ssb_append, unifying_example): * src/lssi.c (lssi_free, lssi_hasher, lssi_comparator) (shortest_path_from_start): * src/parse-simulation.c (free_parse_state) (parse_state_list_new, parser_pop): * src/state-item.c (hash_pair_hasher, hash_pair_comparator) (hash_pair_free, hash_pair_table_create): Avoid undefined behavior in C, which does not allow you to cast a function pointer to some other function type and then call it via that other type. Instead, use functions with correct types according to the C standard, and cast their parameters. * src/getargs.c (xargmatch_fn): Return int const, not int, to match what ARGMATCH_DEFINE_GROUP does. In all uses of ARGMATCH_DEFINE_GROUP, say that they return int, to match xargmatch_fn. (FLAGS_ARGMATCH): Do not cast function pointer. * src/parse-simulation.c (vc_derivation_list_append): New function. * src/system.h (deconst): New static function.
This commit is contained in:
@@ -69,7 +69,7 @@ const char *skeleton = NULL;
|
||||
int language_prio = default_prio;
|
||||
struct bison_language const *language = &valid_languages[0];
|
||||
|
||||
typedef int* (xargmatch_fn) (const char *context, const char *arg);
|
||||
typedef int const *(xargmatch_fn) (char const *context, char const *arg);
|
||||
|
||||
void
|
||||
set_yacc (location loc)
|
||||
@@ -164,7 +164,7 @@ flags_argmatch (const char *opt,
|
||||
*/
|
||||
#define FLAGS_ARGMATCH(FlagName, Args, All) \
|
||||
flags_argmatch ("--" #FlagName, \
|
||||
(xargmatch_fn*) argmatch_## FlagName ## _value, \
|
||||
argmatch_ ## FlagName ## _value, \
|
||||
argmatch_ ## FlagName ## _usage, \
|
||||
All, &FlagName ## _flag, Args)
|
||||
|
||||
@@ -179,7 +179,7 @@ enum color
|
||||
color_auto
|
||||
};
|
||||
|
||||
ARGMATCH_DEFINE_GROUP (color, enum color)
|
||||
ARGMATCH_DEFINE_GROUP (color, int)
|
||||
|
||||
static const argmatch_color_doc argmatch_color_docs[] =
|
||||
{
|
||||
@@ -215,7 +215,7 @@ const argmatch_color_group_type argmatch_color_group =
|
||||
| --report's handling. |
|
||||
`----------------------*/
|
||||
|
||||
ARGMATCH_DEFINE_GROUP (report, enum report)
|
||||
ARGMATCH_DEFINE_GROUP (report, int)
|
||||
|
||||
static const argmatch_report_doc argmatch_report_docs[] =
|
||||
{
|
||||
@@ -256,7 +256,7 @@ const argmatch_report_group_type argmatch_report_group =
|
||||
| --trace's handling. |
|
||||
`---------------------*/
|
||||
|
||||
ARGMATCH_DEFINE_GROUP (trace, enum trace)
|
||||
ARGMATCH_DEFINE_GROUP (trace, int)
|
||||
|
||||
static const argmatch_trace_doc argmatch_trace_docs[] =
|
||||
{
|
||||
@@ -319,7 +319,7 @@ const argmatch_trace_group_type argmatch_trace_group =
|
||||
| --feature's handling. |
|
||||
`-----------------------*/
|
||||
|
||||
ARGMATCH_DEFINE_GROUP (feature, enum feature)
|
||||
ARGMATCH_DEFINE_GROUP (feature, int)
|
||||
|
||||
static const argmatch_feature_doc argmatch_feature_docs[] =
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user