diff mbox series

[1/9] metaparse: Print parsing file on verbose

Message ID 20240104204614.1426027-2-pvorel@suse.cz
State Changes Requested
Headers show
Series metadata: improvements | expand

Commit Message

Petr Vorel Jan. 4, 2024, 8:46 p.m. UTC
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 metadata/metaparse.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Petr Vorel Jan. 5, 2024, 12:03 p.m. UTC | #1
Hi all,

> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  metadata/metaparse.c | 3 +++
>  1 file changed, 3 insertions(+)

> diff --git a/metadata/metaparse.c b/metadata/metaparse.c
> index 2384c73c8..fe6d68911 100644
> --- a/metadata/metaparse.c
> +++ b/metadata/metaparse.c
> @@ -862,6 +862,9 @@ int main(int argc, char *argv[])
>  		return 1;
>  	}

> +	if (verbose)
> +		fprintf(stderr, "\n=== %s ===\n", argv[optind]);
> +

This introduces warning:

$ make metaparse
In file included from metaparse.c:17:
In function ‘data_node_string’,
    inlined from ‘main’ at metaparse.c:894:6:
data_storage.h:84:20: warning: array subscript ‘struct data_node[0]’ is partly outside array bounds of ‘unsigned char[6]’ [-Warray-bounds=]
   84 |         node->type = DATA_STRING;
      |         ~~~~~~~~~~~^~~~~~~~~~~~~
data_storage.h:79:34: note: object of size 6 allocated by ‘malloc’
   79 |         struct data_node *node = malloc(size);
      |                                  ^~~~~~~~~~~~
HOSTCC metadata/metaparse

What am I missing?

>  	res = parse_file(argv[optind]);
>  	if (!res)
>  		return 0;
Cyril Hrubis Feb. 23, 2024, 12:12 p.m. UTC | #2
Hi!
> This introduces warning:
> 
> $ make metaparse
> In file included from metaparse.c:17:
> In function ‘data_node_string’,
>     inlined from ‘main’ at metaparse.c:894:6:
> data_storage.h:84:20: warning: array subscript ‘struct data_node[0]’ is partly outside array bounds of ‘unsigned char[6]’ [-Warray-bounds=]
>    84 |         node->type = DATA_STRING;
>       |         ~~~~~~~~~~~^~~~~~~~~~~~~
> data_storage.h:79:34: note: object of size 6 allocated by ‘malloc’
>    79 |         struct data_node *node = malloc(size);
>       |                                  ^~~~~~~~~~~~
> HOSTCC metadata/metaparse
> 
> What am I missing?

This looks like the compiler is confused by the union and flexible array
and static analysis produces gibberish. The very fact that this is
triggered by addition of unrelated piece of code supports that hypotesis
as well.
Cyril Hrubis Feb. 23, 2024, 12:24 p.m. UTC | #3
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Petr Vorel Feb. 23, 2024, 1:51 p.m. UTC | #4
> Hi!
> > This introduces warning:

> > $ make metaparse
> > In file included from metaparse.c:17:
> > In function ‘data_node_string’,
> >     inlined from ‘main’ at metaparse.c:894:6:
> > data_storage.h:84:20: warning: array subscript ‘struct data_node[0]’ is partly outside array bounds of ‘unsigned char[6]’ [-Warray-bounds=]
> >    84 |         node->type = DATA_STRING;
> >       |         ~~~~~~~~~~~^~~~~~~~~~~~~
> > data_storage.h:79:34: note: object of size 6 allocated by ‘malloc’
> >    79 |         struct data_node *node = malloc(size);
> >       |                                  ^~~~~~~~~~~~
> > HOSTCC metadata/metaparse

> > What am I missing?

> This looks like the compiler is confused by the union and flexible array
> and static analysis produces gibberish. The very fact that this is
> triggered by addition of unrelated piece of code supports that hypotesis
> as well.

Thanks for info. So really false positive? Therefore we have nothing to improve
and we should report to gcc?

Kind regards,
Petr
diff mbox series

Patch

diff --git a/metadata/metaparse.c b/metadata/metaparse.c
index 2384c73c8..fe6d68911 100644
--- a/metadata/metaparse.c
+++ b/metadata/metaparse.c
@@ -862,6 +862,9 @@  int main(int argc, char *argv[])
 		return 1;
 	}
 
+	if (verbose)
+		fprintf(stderr, "\n=== %s ===\n", argv[optind]);
+
 	res = parse_file(argv[optind]);
 	if (!res)
 		return 0;