linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sparse: Use offsetof macro to silence null ptr subtraction warning
@ 2022-03-21 11:21 Richard Palethorpe
  2022-05-21 13:28 ` Luc Van Oostenryck
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Palethorpe @ 2022-03-21 11:21 UTC (permalink / raw)
  To: linux-sparse; +Cc: ltp, Richard Palethorpe

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] sparse: Use offsetof macro to silence null ptr subtraction warning
  2022-03-21 11:21 [PATCH] sparse: Use offsetof macro to silence null ptr subtraction warning Richard Palethorpe
@ 2022-05-21 13:28 ` Luc Van Oostenryck
  0 siblings, 0 replies; 2+ messages in thread
From: Luc Van Oostenryck @ 2022-05-21 13:28 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: linux-sparse, ltp

On Mon, Mar 21, 2022 at 11:21:19AM +0000, Richard Palethorpe wrote:
> Subtracting (char *)0 is undefined behavior. Newer compilers warn
> about this unless it is done in system headers.

Thanks you, pushed now.

-- Luc 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-21 13:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-21 11:21 [PATCH] sparse: Use offsetof macro to silence null ptr subtraction warning Richard Palethorpe
2022-05-21 13:28 ` Luc Van Oostenryck

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 NNTP newsgroup(s).