All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sparse: Use offsetof macro to silence null ptr subtraction warning
@ 2022-03-21 11:21 ` Richard Palethorpe via ltp
  0 siblings, 0 replies; 4+ 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] 4+ messages in thread

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

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

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

* Re: [PATCH] sparse: Use offsetof macro to silence null ptr subtraction warning
  2022-03-21 11:21 ` [LTP] " Richard Palethorpe via ltp
@ 2022-05-21 13:28   ` Luc Van Oostenryck
  -1 siblings, 0 replies; 4+ 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] 4+ messages in thread

* Re: [LTP] [PATCH] sparse: Use offsetof macro to silence null ptr subtraction warning
@ 2022-05-21 13:28   ` Luc Van Oostenryck
  0 siblings, 0 replies; 4+ 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 

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

end of thread, other threads:[~2022-05-26 11:01 UTC | newest]

Thread overview: 4+ 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-03-21 11:21 ` [LTP] " Richard Palethorpe via ltp
2022-05-21 13:28 ` Luc Van Oostenryck
2022-05-21 13:28   ` [LTP] " Luc Van Oostenryck

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.