Message ID | 20220321112119.23308-1-rpalethorpe@suse.com (mailing list archive) |
---|---|
State | Mainlined, archived |
Headers | show |
Series | sparse: Use offsetof macro to silence null ptr subtraction warning | expand |
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
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; }
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(-)