Introduce ARRAY_SIZE() macro
* 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.
This commit is contained in:
parent
732f39656d
commit
fcda7a5f4f
2
defs.h
2
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 */
|
||||
|
6
ioctl.c
6
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;
|
||||
|
16
pathtrace.c
16
pathtrace.c
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
6
signal.c
6
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;
|
||||
|
21
syscall.c
21
syscall.c
@ -114,14 +114,14 @@
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user