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:
Paul Eggert
2025-03-13 13:38:21 -07:00
parent 6a4b3240cf
commit d7527048a8
9 changed files with 90 additions and 70 deletions

View File

@@ -194,8 +194,9 @@ parse_state_free_contents_early (parse_state *ps)
}
void
free_parse_state (parse_state *original_ps)
free_parse_state (void const *voriginal_ps)
{
parse_state *original_ps = deconst (voriginal_ps);
bool free_contents = true;
parse_state *parent_ps = NULL;
for (parse_state *ps = original_ps; ps && free_contents; ps = parent_ps)
@@ -311,8 +312,7 @@ static parse_state_list
parse_state_list_new (void)
{
return gl_list_create_empty (GL_LINKED_LIST, NULL, NULL,
(gl_listelement_dispose_fn)free_parse_state,
true);
free_parse_state, true);
}
static void
@@ -322,6 +322,13 @@ parse_state_list_append (parse_state_list pl, parse_state *ps)
gl_list_add_last (pl, ps);
}
static void
vc_derivation_list_append (derivation_list dl, void const *vcd)
{
derivation *d = deconst (vcd);
return derivation_list_append (dl, d);
}
// Emulates a reduction on a parse state by popping some amount of
// derivations and state_items off of the parse_state and returning
// the result in ret. Returns the derivation of what's popped.
@@ -351,7 +358,7 @@ parser_pop (parse_state *ps, int deriv_index,
list_flatten_and_split (chunks, ret_chunks, si_index, 2,
list_add_last);
list_flatten_and_split (chunks + 2, ret_chunks + 2, deriv_index, 2,
(chunk_append_fn)derivation_list_append);
vc_derivation_list_append);
size_t s_size = gl_list_size (ret->state_items.contents);
ret->state_items.total_size = s_size;
if (s_size > 0)