]> granicus.if.org Git - strace/commitdiff
Introduce ARRAY_SIZE() macro
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 13 Jun 2011 21:58:43 +0000 (21:58 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 13 Jun 2011 21:58:43 +0000 (21:58 +0000)
* defs.h (ARRAY_SIZE): New macro.
* ioctl.c: Use it.
* pathtrace.c (pathmatch, storepath): Likewise.
* process.c (printpriv): Likewise.
* signal.c: Likewise.
* syscall.c: Likewise.

defs.h
ioctl.c
pathtrace.c
process.c
signal.c
syscall.c

diff --git a/defs.h b/defs.h
index 33904949994812ce7bd26b80db2c5c47c4b63e58..2c086357b66374c6d119df03cdffb0ed7fe3efdc 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -343,6 +343,8 @@ extern int mp_ioctl(int f, int c, void *a, int s);
 # define __attribute__(x) /*nothing*/
 #endif
 
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
 /* Trace Control Block */
 struct tcb {
        short flags;            /* See below for TCB_ values */
diff --git a/ioctl.c b/ioctl.c
index 0d991f8ac756f787acde650e1295975390f2c42e..d7927c65819763b3ab68ebc431f2cc6ac9a4d25d 100644 (file)
--- a/ioctl.c
+++ b/ioctl.c
@@ -47,14 +47,14 @@ const struct ioctlent ioctlent0[] = {
 #include <asm/ioctl.h>
 #endif
 
-const int nioctlents0 = sizeof ioctlent0 / sizeof ioctlent0[0];
+const int nioctlents0 = ARRAY_SIZE(ioctlent0);
 
 #if SUPPORTED_PERSONALITIES >= 2
 const struct ioctlent ioctlent1[] = {
 #include "ioctlent1.h"
 };
 
-const int nioctlents1 = sizeof ioctlent1 / sizeof ioctlent1[0];
+const int nioctlents1 = ARRAY_SIZE(ioctlent1);
 #endif /* SUPPORTED_PERSONALITIES >= 2 */
 
 #if SUPPORTED_PERSONALITIES >= 3
@@ -62,7 +62,7 @@ const struct ioctlent ioctlent2[] = {
 #include "ioctlent2.h"
 };
 
-const int nioctlents2 = sizeof ioctlent2 / sizeof ioctlent2[0];
+const int nioctlents2 = ARRAY_SIZE(ioctlent2);
 #endif /* SUPPORTED_PERSONALITIES >= 3 */
 
 const struct ioctlent *ioctlent;
index 397f2351eccff90001f3765a6e078db111ce29c3..d8df707e916d94fbf1685260a3a0e8039647abae 100644 (file)
@@ -40,8 +40,6 @@
 
 #include "syscall.h"
 
-#define NumElem(a)  (int)(sizeof(a) / sizeof((a)[0]))
-
 #define MAXSELECTED  256       /* max number of "selected" paths */
 static const char *selected[MAXSELECTED];      /* paths selected for tracing */
 
@@ -51,9 +49,9 @@ static const char *selected[MAXSELECTED];     /* paths selected for tracing */
 static int
 pathmatch(const char *path)
 {
-       int     i;
+       unsigned int i;
 
-       for (i = 0; i < NumElem(selected); ++i)
+       for (i = 0; i < ARRAY_SIZE(selected); ++i)
        {
                if (selected[i] == NULL)
                        return 0;
@@ -93,11 +91,11 @@ fdmatch(struct tcb *tcp, int fd)
 static int
 storepath(const char *path)
 {
-       int     i;
+       unsigned int i;
 
        if (path == NULL)
        {
-               for (i = 0; i < NumElem(selected); ++i)
+               for (i = 0; i < ARRAY_SIZE(selected); ++i)
                        if (selected[i])
                        {
                                free((char *) selected[i]);
@@ -106,15 +104,15 @@ storepath(const char *path)
                return 0;
        }
 
-       for (i = 0; i < NumElem(selected); ++i)
+       for (i = 0; i < ARRAY_SIZE(selected); ++i)
                if (!selected[i])
                {
                        selected[i] = path;
                        return 0;
                }
 
-       fprintf(stderr, "Max trace paths exceeded, only using first %d\n",
-               NumElem(selected));
+       fprintf(stderr, "Max trace paths exceeded, only using first %u\n",
+               (unsigned int) ARRAY_SIZE(selected));
        return -1;
 }
 
index 672bc41c6254da000c2307de8a9f37c21c131166..63f08046a934041de1181fc4acf0d9fd81e493e1 100644 (file)
--- a/process.c
+++ b/process.c
@@ -1569,7 +1569,7 @@ static void
 printpriv(struct tcb *tcp, long addr, int len, const struct xlat *opt)
 {
        priv_t buf[128];
-       int max = verbose(tcp) ? sizeof buf / sizeof buf[0] : 10;
+       int max = verbose(tcp) ? ARRAY_SIZE(buf) : 10;
        int dots = len > max;
        int i;
 
index 85e74b576db00a1fb8c077a8a630aa8502ca9cb7..59a52ca3ba456022b1585f51a4d6e039b9ebc3e2 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -143,20 +143,20 @@ struct sigcontext
 const char *const signalent0[] = {
 #include "signalent.h"
 };
-const int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
+const int nsignals0 = ARRAY_SIZE(signalent0);
 
 #if SUPPORTED_PERSONALITIES >= 2
 const char *const signalent1[] = {
 #include "signalent1.h"
 };
-const int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
+const int nsignals1 = ARRAY_SIZE(signalent1);
 #endif /* SUPPORTED_PERSONALITIES >= 2 */
 
 #if SUPPORTED_PERSONALITIES >= 3
 const char *const signalent2[] = {
 #include "signalent2.h"
 };
-const int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
+const int nsignals2 = ARRAY_SIZE(signalent2);
 #endif /* SUPPORTED_PERSONALITIES >= 3 */
 
 const char *const *signalent;
index c9a5b9f893bc97e0e652411a1b0c833ddcbae4e9..ba2083c3520a0d68ac46fc4bef75daefa23a7437 100644 (file)
--- a/syscall.c
+++ b/syscall.c
 static const struct sysent sysent0[] = {
 #include "syscallent.h"
 };
-static const int nsyscalls0 = sizeof sysent0 / sizeof sysent0[0];
+static const int nsyscalls0 = ARRAY_SIZE(sysent0);
 int qual_flags0[MAX_QUALS];
 
 #if SUPPORTED_PERSONALITIES >= 2
 static const struct sysent sysent1[] = {
 #include "syscallent1.h"
 };
-static const int nsyscalls1 = sizeof sysent1 / sizeof sysent1[0];
+static const int nsyscalls1 = ARRAY_SIZE(sysent1);
 int qual_flags1[MAX_QUALS];
 #endif /* SUPPORTED_PERSONALITIES >= 2 */
 
@@ -129,7 +129,7 @@ int qual_flags1[MAX_QUALS];
 static const struct sysent sysent2[] = {
 #include "syscallent2.h"
 };
-static const int nsyscalls2 = sizeof sysent2 / sizeof sysent2[0];
+static const int nsyscalls2 = ARRAY_SIZE(sysent2);
 int qual_flags2[MAX_QUALS];
 #endif /* SUPPORTED_PERSONALITIES >= 3 */
 
@@ -149,20 +149,20 @@ int nsyscalls;
 static const char *const errnoent0[] = {
 #include "errnoent.h"
 };
-static const int nerrnos0 = sizeof errnoent0 / sizeof errnoent0[0];
+static const int nerrnos0 = ARRAY_SIZE(errnoent0);
 
 #if SUPPORTED_PERSONALITIES >= 2
 static const char *const errnoent1[] = {
 #include "errnoent1.h"
 };
-static const int nerrnos1 = sizeof errnoent1 / sizeof errnoent1[0];
+static const int nerrnos1 = ARRAY_SIZE(errnoent1);
 #endif /* SUPPORTED_PERSONALITIES >= 2 */
 
 #if SUPPORTED_PERSONALITIES >= 3
 static const char *const errnoent2[] = {
 #include "errnoent2.h"
 };
-static const int nerrnos2 = sizeof errnoent2 / sizeof errnoent2[0];
+static const int nerrnos2 = ARRAY_SIZE(errnoent2);
 #endif /* SUPPORTED_PERSONALITIES >= 3 */
 
 const char *const *errnoent;
@@ -596,9 +596,9 @@ decode_subcall(struct tcb *tcp, int subcall, int nsubcalls, enum subcall_style s
                break;
 #ifdef FREEBSD
        case table_style:
-               for (i = 0; i < sizeof(subcalls_table) / sizeof(struct subcall); i++)
+               for (i = 0; i < ARRAY_SIZE(subcalls_table); i++)
                        if (subcalls_table[i].call == tcp->scno) break;
-               if (i < sizeof(subcalls_table) / sizeof(struct subcall) &&
+               if (i < ARRAY_SIZE(subcalls_table) &&
                    tcp->u_arg[0] >= 0 && tcp->u_arg[0] < subcalls_table[i].nsubcalls) {
                        tcp->scno = subcalls_table[i].subcalls[tcp->u_arg[0]];
                        for (i = 0; i < tcp->u_nargs; i++)
@@ -2165,7 +2165,7 @@ syscall_enter(struct tcb *tcp)
                if (tcp->scno >= 0 && tcp->scno < nsyscalls && sysent[tcp->scno].nargs != -1)
                        tcp->u_nargs = sysent[tcp->scno].nargs;
                else
-                       tcp->u_nargs = sizeof(argreg) / sizeof(argreg[0]);
+                       tcp->u_nargs = ARRAY_SIZE(argreg);
 
                for (i = 0; i < tcp->u_nargs; ++i)
                        if (upeek(tcp, argreg[i], &tcp->u_arg[i]) < 0)
@@ -2196,8 +2196,7 @@ syscall_enter(struct tcb *tcp)
                 *       in the trap number matches the number strace expects.
                 */
                /*
-               assert(sysent[tcp->scno].nargs <
-                      sizeof(syscall_regs)/sizeof(syscall_regs[0]));
+               assert(sysent[tcp->scno].nargs < ARRAY_SIZE(syscall_regs));
                 */
 
                tcp->u_nargs = sysent[tcp->scno].nargs;