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
next reply other threads:[~2022-03-21 11:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-21 11:21 Richard Palethorpe [this message]
2022-05-21 13:28 ` [PATCH] sparse: Use offsetof macro to silence null ptr subtraction warning 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: 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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).