From: Richard Palethorpe <rpalethorpe@suse.com> To: linux-sparse@vger.kernel.org Cc: ltp@lists.linux.it, Richard Palethorpe <rpalethorpe@suse.com> Subject: [PATCH] sparse: Use offsetof macro to silence null ptr subtraction warning Date: Mon, 21 Mar 2022 11:21:19 +0000 [thread overview] Message-ID: <20220321112119.23308-1-rpalethorpe@suse.com> (raw) Subtracting (char *)0 is undefined behavior. Newer compilers warn about this unless it is done in system headers. Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com> --- token.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/token.h b/token.h index bccac0e4..9000e0cb 100644 --- a/token.h +++ b/token.h @@ -201,7 +201,7 @@ struct token { static inline struct token *containing_token(struct token **p) { - void *addr = (char *)p - ((char *)&((struct token *)0)->next - (char *)0); + void *addr = (char *)p - offsetof(struct token, next); return addr; } -- 2.35.1
WARNING: multiple messages have this Message-ID (diff)
From: Richard Palethorpe via ltp <ltp@lists.linux.it> To: linux-sparse@vger.kernel.org Cc: Richard Palethorpe <rpalethorpe@suse.com>, ltp@lists.linux.it Subject: [LTP] [PATCH] sparse: Use offsetof macro to silence null ptr subtraction warning Date: Mon, 21 Mar 2022 11:21:19 +0000 [thread overview] Message-ID: <20220321112119.23308-1-rpalethorpe@suse.com> (raw) Subtracting (char *)0 is undefined behavior. Newer compilers warn about this unless it is done in system headers. Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com> --- token.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/token.h b/token.h index bccac0e4..9000e0cb 100644 --- a/token.h +++ b/token.h @@ -201,7 +201,7 @@ struct token { static inline struct token *containing_token(struct token **p) { - void *addr = (char *)p - ((char *)&((struct token *)0)->next - (char *)0); + void *addr = (char *)p - offsetof(struct token, next); return addr; } -- 2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2022-03-21 11:22 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-03-21 11:21 Richard Palethorpe [this message] 2022-03-21 11:21 ` [LTP] [PATCH] sparse: Use offsetof macro to silence null ptr subtraction warning Richard Palethorpe via ltp 2022-05-21 13:28 ` Luc Van Oostenryck 2022-05-21 13:28 ` [LTP] " Luc Van Oostenryck
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=20220321112119.23308-1-rpalethorpe@suse.com \ --to=rpalethorpe@suse.com \ --cc=linux-sparse@vger.kernel.org \ --cc=ltp@lists.linux.it \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.