]> granicus.if.org Git - procps-ng/commitdiff
library: fix 'smaps' bug preventing a build with clang
authorJim Warner <james.warner@comcast.net>
Sun, 10 Apr 2022 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Mon, 11 Apr 2022 06:41:12 +0000 (16:41 +1000)
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 <james.warner@comcast.net>
NEWS
proc/readproc.c

diff --git a/NEWS b/NEWS
index aef9c1a74c84b6e3e74517e0b3f037afbc67a5c0..706621031d4628374470a170ec086ef86070523b 100644 (file)
--- 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
 ---------------
index 41888cca4444b8eeffb0ad7f059e1de7752af203..bf1606d655a47a649658ddf4a9f3ad0c02b7fc59 100644 (file)
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -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;