From: Cyril Hrubis <chrubis@suse.cz>
To: Petr Vorel <pvorel@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [RFC PATCH 1/1] metaparse: mntpoint implies needs_tmpdir
Date: Mon, 2 Sep 2024 13:55:59 +0200 [thread overview]
Message-ID: <ZtWnz_Me7UbAYIVV@yuki.lan> (raw)
In-Reply-To: <20240902080330.356551-1-pvorel@suse.cz>
Hi!
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>
> I see lib/tst_test.c
> static int needs_tmpdir(void)
> {
> return tst_test->needs_tmpdir ||
> tst_test->needs_device ||
> tst_test->mntpoint ||
> tst_test->resource_files ||
> tst_test->needs_checkpoints;
> }
>
> But
> 1) It does not detect it.
> 2) -Warray-bounds is introduced.
>
> What am I missing?
> I originally come to this via
> https://patchwork.ozlabs.org/project/ltp/patch/20240829114124.30299-1-wegao@suse.com/
> (where IMHO .needs_tmpdir = 1 is not needed due .mntpoint)
>
> $ cat > foo.c <<EOF
> #define MNTPOINT "mntpoint"
> #include "tst_test.h"
>
> static void do_test(void)
> {
> tst_res(TPASS, "foo");
> }
> EOF
>
> static struct tst_test test = {
> .test_all = do_test,
> .mntpoint = MNTPOINT,
> };
>
> $ cd metadata; make metaparse && ./metaparse -I../include -I../testcases/kernel/syscalls/utils/ ../foo.c
> In file included from metaparse.c:17:
> In function ‘data_node_string’,
> inlined from ‘main’ at metaparse.c:892: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);
> | ^~~~~~~~~~~~
This seems to be one of the gcc bugs, where you shuffle code a little
bit and it triggers useless warnings. I guess that the compiler is
confused by the union usage. It goes away if you rewrite the code as:
diff --git a/metadata/data_storage.h b/metadata/data_storage.h
index 91ea70a02..cc9f9f233 100644
--- a/metadata/data_storage.h
+++ b/metadata/data_storage.h
@@ -81,8 +81,10 @@ static inline struct data_node *data_node_string(const char *string)
if (!node)
return NULL;
- node->type = DATA_STRING;
- strcpy(node->string.val, string);
+ struct data_node_string *str_node = &node->string;
+
+ str_node->type = DATA_STRING;
+ strcpy(str_node->val, string);
Also it seems that clang is smart enough not to produce the warnings.
> HOSTCC metadata/metaparse
> "foo": {
> "fname": ".../foo.c"
>
> metadata/metaparse.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/metadata/metaparse.c b/metadata/metaparse.c
> index 2384c73c86..24bf0f0968 100644
> --- a/metadata/metaparse.c
> +++ b/metadata/metaparse.c
> @@ -801,6 +801,7 @@ static struct implies {
> NULL}},
> {"all_filesystems", (const char *[]) {"needs_device", "needs_tmpdir",
> NULL}},
> + {"mntpoint", (const char *[]) {"needs_tmpdir", NULL}},
> {"needs_device", (const char *[]) {"needs_tmpdir", NULL}},
> {"needs_checkpoints", (const char *[]) {"needs_tmpdir", NULL}},
> {"resource_files", (const char *[]) {"needs_tmpdir", NULL}},
> --
> 2.45.2
>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2024-09-02 11:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-02 8:03 [LTP] [RFC PATCH 1/1] metaparse: mntpoint implies needs_tmpdir Petr Vorel
2024-09-02 11:55 ` Cyril Hrubis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZtWnz_Me7UbAYIVV@yuki.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=pvorel@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox