Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gcc warnings #842

Merged
merged 4 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl
dnl Taken from libvirt/acinclude.m4
dnl
dnl We've added:
dnl -Wextra -Wshadow -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Winline -Wredundant-decls
dnl -Wextra -Wshadow -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wredundant-decls
dnl We've removed
dnl CFLAGS="$realsave_CFLAGS"
dnl to avoid clobbering user-specified CFLAGS
Expand Down Expand Up @@ -34,7 +34,7 @@ AC_DEFUN([AUGEAS_COMPILE_WARNINGS],[
maximum|error)
try_compiler_flags="-Wall -Wformat -Wformat-security -Wmissing-prototypes -Wnested-externs -Wpointer-arith"
try_compiler_flags="$try_compiler_flags -Wextra -Wshadow -Wcast-align -Wwrite-strings -Waggregate-return"
try_compiler_flags="$try_compiler_flags -Wstrict-prototypes -Winline -Wredundant-decls -Wno-sign-compare"
try_compiler_flags="$try_compiler_flags -Wstrict-prototypes -Wredundant-decls -Wno-sign-compare"
try_compiler_flags="$try_compiler_flags $common_flags"
if test "$enable_compile_warnings" = "error" ; then
try_compiler_flags="$try_compiler_flags -Werror"
Expand Down
24 changes: 12 additions & 12 deletions src/augprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ static struct group *find_or_create_group(char *head) {
/* First, grow all_groups[] array if required */
if ( num_groups % 32 == 0 ) {
num_groups_newsize = (num_groups)/32*32+32;
all_groups_realloc = reallocarray(all_groups, sizeof(struct group *), num_groups_newsize);
all_groups_realloc = reallocarray(all_groups, num_groups_newsize, sizeof(struct group *));
CHECK_OOM( ! all_groups_realloc, exit_oom, "in find_or_create_group()");

all_groups=all_groups_realloc;
Expand Down Expand Up @@ -523,10 +523,10 @@ static struct tail *find_or_create_tail(struct group *group, struct path_segment
tail = malloc(sizeof(struct tail));
CHECK_OOM( ! tail, exit_oom, "in find_or_create_tail()");

tail->tail_found_map = reallocarray(NULL, sizeof(unsigned int), group->position_array_size);
tail->tail_found_map = reallocarray(NULL, group->position_array_size, sizeof(unsigned int));
CHECK_OOM( ! tail->tail_found_map, exit_oom, "in find_or_create_tail()");

tail->tail_value_found_map = reallocarray(NULL, sizeof(unsigned int), group->position_array_size);
tail->tail_value_found_map = reallocarray(NULL, group->position_array_size, sizeof(unsigned int));
CHECK_OOM( ! tail->tail_value_found_map, exit_oom, "in find_or_create_tail()");


Expand Down Expand Up @@ -584,13 +584,13 @@ static void grow_position_arrays(struct group *group, unsigned int new_max_posit
unsigned int new_size = (new_max_position+1) / 8 * 8 + 8;

/* Grow arrays within struct group */
tails_at_position_realloc = reallocarray(group->tails_at_position, sizeof(struct tail_stub *), new_size);
chosen_tail_realloc = reallocarray(group->chosen_tail, sizeof(struct tail *), new_size);
first_tail_realloc = reallocarray(group->first_tail, sizeof(struct tail_stub *), new_size);
chosen_tail_state_realloc = reallocarray(group->chosen_tail_state, sizeof(chosen_tail_state_t), new_size);
pretty_width_ct_realloc = reallocarray(group->pretty_width_ct, sizeof(unsigned int), new_size);
re_width_ct_realloc = reallocarray(group->re_width_ct, sizeof(unsigned int), new_size);
re_width_ft_realloc = reallocarray(group->re_width_ft, sizeof(unsigned int), new_size);
tails_at_position_realloc = reallocarray(group->tails_at_position, new_size, sizeof(struct tail_stub *));
chosen_tail_realloc = reallocarray(group->chosen_tail, new_size, sizeof(struct tail *));
first_tail_realloc = reallocarray(group->first_tail, new_size, sizeof(struct tail_stub *));
chosen_tail_state_realloc = reallocarray(group->chosen_tail_state, new_size, sizeof(chosen_tail_state_t));
pretty_width_ct_realloc = reallocarray(group->pretty_width_ct, new_size, sizeof(unsigned int));
re_width_ct_realloc = reallocarray(group->re_width_ct, new_size, sizeof(unsigned int));
re_width_ft_realloc = reallocarray(group->re_width_ft, new_size, sizeof(unsigned int));
CHECK_OOM( ! tails_at_position_realloc || ! chosen_tail_realloc || ! chosen_tail_state_realloc ||
! pretty_width_ct_realloc || ! re_width_ct_realloc || ! re_width_ft_realloc ||
! first_tail_realloc, exit_oom, "in grow_position_arrays()");
Expand All @@ -617,8 +617,8 @@ static void grow_position_arrays(struct group *group, unsigned int new_max_posit
for( tail = group->all_tails; tail != NULL; tail=tail->next ) {
unsigned int *tail_found_map_realloc;
unsigned int *tail_value_found_map_realloc;
tail_found_map_realloc = reallocarray(tail->tail_found_map, sizeof(unsigned int), new_size);
tail_value_found_map_realloc = reallocarray(tail->tail_value_found_map, sizeof(unsigned int), new_size);
tail_found_map_realloc = reallocarray(tail->tail_found_map, new_size, sizeof(unsigned int));
tail_value_found_map_realloc = reallocarray(tail->tail_value_found_map, new_size, sizeof(unsigned int));
CHECK_OOM( ! tail_found_map_realloc || ! tail_value_found_map_realloc, exit_oom, "in grow_position_arrays()");

/* initialize array entries between old size to new_size */
Expand Down
7 changes: 7 additions & 0 deletions src/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,14 @@ static struct frame *push_frame(struct rec_state *state, struct lens *lens) {
state->fused += 1;

struct frame *top = top_frame(state);
/* GCC 14.2.1 cannot analyze this correctly, so it breaks with
* -Werror. Until this is fixed in GCC, disable the warning.
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#pragma GCC diagnostic ignored "-Wstringop-overflow"
MEMZERO(top, 1);
#pragma GCC diagnostic pop
top->lens = lens;
return top;
error:
Expand Down
2 changes: 1 addition & 1 deletion tests/test-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ static void testAugPreview(CuTest *tc) {
if (asprintf(&etc_hosts_fn,"%s/etc/hosts",root) >=0 ) {
hosts_fp = fopen(etc_hosts_fn,"r");
if ( hosts_fp ) {
hosts_txt = calloc(sizeof(char),4096);
hosts_txt = calloc(4096,sizeof(char));
if ( hosts_txt ) {
readsz = fread(hosts_txt,sizeof(char),4096,hosts_fp);
*(hosts_txt+readsz) = '\0';
Expand Down