From 9e77e138c16919162bc6ac78f7eebd1db9c518f7 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Sun, 10 Apr 2022 00:00:00 -0500 Subject: [PATCH] library: fix 'smaps' bug preventing a build with clang As a result of the issue referenced below, we'll trade our homegrown offset generator for an 'offsetof' macro found in the stddef.h header file. This pleases clang. [ and thanks to Daniel Kolesa for the report and fix ] Reference(s): . bug report & recommended solution https://gitlab.com/procps-ng/procps/-/issues/235 . clang error message proc/readproc.c:673:9: error: initializer element is not a compile-time constant mkENT(Rss), ^~~~~~~~~~ proc/readproc.c:661:34: note: expanded from macro 'mkENT' #define mkENT(F) { #F ":", -1, (int)((void*)&q->smap_ ## F - (void*)&q->fZERO) } ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jim Warner --- NEWS | 1 + proc/readproc.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index aef9c1a7..70662103 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ procps-ng-NEXT * ps: threads again display when -L is used with -q issue #234 * ps: proper aix format string behavior was restored * sysctl: print dotted keys again + * top: fix 'smaps' bug preventing build under clang issue #235 procps-ng-4.0.0 --------------- diff --git a/proc/readproc.c b/proc/readproc.c index 41888cca..bf1606d6 100644 --- a/proc/readproc.c +++ b/proc/readproc.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include #include @@ -658,10 +659,9 @@ static void smaps2proc (const char *s, proc_t *restrict P) { // 1st proc_t data field #define fZERO tid // a smaptab entry generator - #define mkENT(F) { #F ":", -1, (int)((void*)&q->smap_ ## F - (void*)&q->fZERO) } + #define mkENT(F) { #F ":", -1, offsetof(proc_t, smap_ ## F) } // make a target field #define mkOBJ(X) ( (unsigned long *)((void *)&P->fZERO + smaptab[X].offs) ) - static const proc_t *q; static struct { const char *item; int slen;