From 0be98daa3135252fcd2b452b45873de50c7f2788 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 6 Aug 2024 17:25:28 +0100 Subject: [PATCH 1/4] src/augprint.c: Fix reallocarray warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 14.2.1 gives lots of warnings of this sort about the order of parameters of reallocarray being the wrong way round: augprint.c: In function ‘find_or_create_group’: augprint.c:462:60: error: ‘reallocarray’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args] 462 | all_groups_realloc = reallocarray(all_groups, sizeof(struct group *), num_groups_newsize); | ^~~~~~ augprint.c:462:60: note: earlier argument should specify number of elements, later size of each element Signed-off-by: Richard W.M. Jones --- src/augprint.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/augprint.c b/src/augprint.c index 560e1a97e..aaec8f3d5 100644 --- a/src/augprint.c +++ b/src/augprint.c @@ -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; @@ -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()"); @@ -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()"); @@ -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 */ From d56f9541479b3023bf467bebef31d445791311fc Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 6 Aug 2024 17:28:35 +0100 Subject: [PATCH 2/4] acinclude.m4: Disable -Winline warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 14.2.1 gives warnings like: In file included from memory.h:26, from augmatch.c:30: In function ‘guess_lens_name’, inlined from ‘main’ at augmatch.c:396:16: internal.h:229:19: error: inlining failed in call to ‘streqv’: call is unlikely and code size would grow [-Werror=inline] 229 | static inline int streqv(const char *a, const char *b) { | ^~~~~~ augmatch.c:294:9: note: called from here 294 | if (streqv(ext, ".json")) { | ^~~~~~~~~~~~~~~~~~~~ These warnings don't seem very useful in Augeas, since we are not so sensitive to code size and don't care about inlining "purity". Rather than attempting to "fix" code which isn't really broken, I chose to disable an unhelpful warning. Signed-off-by: Richard W.M. Jones --- acinclude.m4 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 31988b1d4..68e850ec4 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -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 @@ -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" From 80ed4c7384437d0bef41337c50180f796a09958e Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 6 Aug 2024 17:36:25 +0100 Subject: [PATCH 3/4] src/get.c: Disable false GCC warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 14.2.1 doesn't seem to be able to analyze this stack frame code correctly. When compiling augeas with --enable-compile-warnings=error that causes the build to fail with the errors below. Disable the error around this code. In file included from /usr/include/string.h:548, from ../gnulib/lib/string.h:41, from internal.h:31, from get.c:30: In function ‘memset’, inlined from ‘push_frame’ at get.c:1095:5: /usr/include/bits/string_fortified.h:59:10: error: ‘__builtin_memset’ offset [0, 31] is out of the bounds [0, 0] [-Werror=array-bounds=] 59 | return __builtin___memset_chk (__dest, __ch, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 60 | __glibc_objsize0 (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ If you disable -Warray-bounds only then you get this instead: In file included from /usr/include/string.h:548, from ../gnulib/lib/string.h:41, from internal.h:31, from get.c:30: In function ‘memset’, inlined from ‘push_frame’ at get.c:1100:5: /usr/include/bits/string_fortified.h:59:10: error: ‘__builtin_memset’ writing 32 bytes into a region of size 0 overflows the destination [-Werror=stringop-overflow=] 59 | return __builtin___memset_chk (__dest, __ch, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 60 | __glibc_objsize0 (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ In function ‘push_frame’: cc1: note: destination object is likely at address zero Signed-off-by: Richard W.M. Jones --- src/get.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/get.c b/src/get.c index 94b9ba24c..76a3c0cbf 100644 --- a/src/get.c +++ b/src/get.c @@ -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: From 87bbea41f8f4305a7ef75e1334d3816e03fe58a0 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 6 Aug 2024 17:40:26 +0100 Subject: [PATCH 4/4] tests/test-api.c: Fix calloc warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 14.2.1 gives: test-api.c: In function ‘testAugPreview’: test-api.c:867:39: error: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args] 867 | hosts_txt = calloc(sizeof(char),4096); | ^~~~ test-api.c:867:39: note: earlier argument should specify number of elements, later size of each element Signed-off-by: Richard W.M. Jones --- tests/test-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-api.c b/tests/test-api.c index 4833dfae3..88a7f55ca 100644 --- a/tests/test-api.c +++ b/tests/test-api.c @@ -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';