stable-2.02 - libdm: fix dm_list pointer arithmentic for new gcc 10 optimization

Zdenek Kabelac <[email protected]>
Newsgroups dev.linux.lists.lvm-devel
Message-ID <[email protected]>
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=8f3d2d5e11305b5f3fc7ced7bd2f81412c9e7d93
Commit:        8f3d2d5e11305b5f3fc7ced7bd2f81412c9e7d93
Parent:        2e3791b421a773b637705a3ca7a2ffc4efc8c873
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Wed Mar 4 16:07:22 2020 +0100
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Wed Apr 8 15:22:54 2020 +0200

libdm: fix dm_list pointer arithmentic for new gcc 10 optimization

---
 libdm/libdevmapper.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index 18fe9f9fd..03a43eb45 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <stddef.h> /* offsetof */
 
 #ifndef __GNUC__
 # define __typeof__ typeof
@@ -2470,7 +2471,7 @@ struct dm_list *dm_list_next(const struct dm_list *head, const struct dm_list *e
  * contained in a structure of type t, return the containing structure.
  */
 #define dm_list_struct_base(v, t, head) \
-    ((t *)((const char *)(v) - (const char *)&((t *) 0)->head))
+    ((t *)((const char *)(v) - offsetof(t, head)))
 
 /*
  * Given the address v of an instance of 'struct dm_list list' contained in
@@ -2483,7 +2484,7 @@ struct dm_list *dm_list_next(const struct dm_list *head, const struct dm_list *e
  * return another element f.
  */
 #define dm_struct_field(v, t, e, f) \
-    (((t *)((uintptr_t)(v) - (uintptr_t)&((t *) 0)->e))->f)
+    (((t *)((uintptr_t)(v) - offsetof(t, e))->f)
 
 /*
  * Given the address v of a known element e in a known structure of type t,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.