Use ARRAY_SIZE all over the tree

Roundhouse kick replacing the various (sizeof(foo)/sizeof(foo[0])) with
the ARRAY_SIZE macro from dix.h when possible. A semantic patch for
coccinelle has been used first. Additionally, a few macros have been
inlined as they had only one or two users.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
This commit is contained in:
Daniel Martin 2017-10-27 16:11:56 +02:00 committed by Adam Jackson
parent 15a32ee5d1
commit d5379b350f
44 changed files with 66 additions and 105 deletions

View File

@ -47,7 +47,6 @@ static const int version_requests[] = {
/* Forward declarations */
static void SGEGenericEvent(xEvent *from, xEvent *to);
#define NUM_VERSION_REQUESTS (sizeof (version_requests) / sizeof (version_requests[0]))
#define EXT_MASK(ext) ((ext) & 0x7F)
/************************************************************/
@ -127,7 +126,7 @@ ProcGEDispatch(ClientPtr client)
REQUEST(xGEReq);
if (pGEClient->major_version >= NUM_VERSION_REQUESTS)
if (pGEClient->major_version >= ARRAY_SIZE(version_requests))
return BadRequest;
if (stuff->ReqType > version_requests[pGEClient->major_version])
return BadRequest;

View File

@ -1268,14 +1268,12 @@ ProcScreenSaverQueryVersion,
ProcScreenSaverSetAttributes,
ProcScreenSaverUnsetAttributes, ProcScreenSaverSuspend,};
#define NUM_REQUESTS ((sizeof NormalVector) / (sizeof NormalVector[0]))
static int
ProcScreenSaverDispatch(ClientPtr client)
{
REQUEST(xReq);
if (stuff->data < NUM_REQUESTS)
if (stuff->data < ARRAY_SIZE(NormalVector))
return (*NormalVector[stuff->data]) (client);
return BadRequest;
}
@ -1360,7 +1358,7 @@ SProcScreenSaverDispatch(ClientPtr client)
{
REQUEST(xReq);
if (stuff->data < NUM_REQUESTS)
if (stuff->data < ARRAY_SIZE(NormalVector))
return (*SwappedVector[stuff->data]) (client);
return BadRequest;
}

View File

@ -372,8 +372,7 @@ XIGetKnownProperty(const char *name)
if (!name)
return None;
for (i = 0; i < (sizeof(dev_properties) / sizeof(struct dev_properties));
i++) {
for (i = 0; i < ARRAY_SIZE(dev_properties); i++) {
if (strcmp(name, dev_properties[i].name) == 0) {
if (dev_properties[i].type == None) {
dev_properties[i].type =
@ -393,8 +392,7 @@ XIResetProperties(void)
{
int i;
for (i = 0; i < (sizeof(dev_properties) / sizeof(struct dev_properties));
i++)
for (i = 0; i < ARRAY_SIZE(dev_properties); i++)
dev_properties[i].type = None;
}

View File

@ -284,9 +284,6 @@ static CompAlternateVisual altVisuals[] = {
{32, PICT_a8r8g8b8},
};
static const int NUM_COMP_ALTERNATE_VISUALS = sizeof(altVisuals) /
sizeof(CompAlternateVisual);
static Bool
compAddAlternateVisual(ScreenPtr pScreen, CompScreenPtr cs,
CompAlternateVisual * alt)
@ -362,7 +359,7 @@ compAddAlternateVisuals(ScreenPtr pScreen, CompScreenPtr cs)
{
int alt, ret = 0;
for (alt = 0; alt < NUM_COMP_ALTERNATE_VISUALS; alt++)
for (alt = 0; alt < ARRAY_SIZE(altVisuals); alt++)
ret |= compAddAlternateVisual(pScreen, cs, altVisuals + alt);
return ! !ret;

View File

@ -464,8 +464,6 @@ static const int version_requests[] = {
X_DamageAdd, /* Version 1 */
};
#define NUM_VERSION_REQUESTS (sizeof (version_requests) / sizeof (version_requests[0]))
static int (*ProcDamageVector[XDamageNumberRequests]) (ClientPtr) = {
/*************** Version 1 ******************/
ProcDamageQueryVersion,
@ -482,7 +480,7 @@ ProcDamageDispatch(ClientPtr client)
REQUEST(xDamageReq);
DamageClientPtr pDamageClient = GetDamageClient(client);
if (pDamageClient->major_version >= NUM_VERSION_REQUESTS)
if (pDamageClient->major_version >= ARRAY_SIZE(version_requests))
return BadRequest;
if (stuff->damageReqType > version_requests[pDamageClient->major_version])
return BadRequest;

View File

@ -655,9 +655,7 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
btlen = bytes_to_int32(bits_to_bytes(MAX_BUTTONS));
len += btlen * 4; /* buttonmask len */
vallen =
count_bits(ev->valuators.mask,
sizeof(ev->valuators.mask) / sizeof(ev->valuators.mask[0]));
vallen = count_bits(ev->valuators.mask, ARRAY_SIZE(ev->valuators.mask));
len += vallen * 2 * sizeof(uint32_t); /* axisvalues */
vallen = bytes_to_int32(bits_to_bytes(MAX_VALUATORS));
len += vallen * 4; /* valuators mask */

View File

@ -439,7 +439,7 @@ ChangeGCXIDs(ClientPtr client, GC * pGC, BITS32 mask, CARD32 *pC32)
}
for (i = Ones(mask); i--;)
vals[i].val = pC32[i];
for (i = 0; i < sizeof(xidfields) / sizeof(*xidfields); ++i) {
for (i = 0; i < ARRAY_SIZE(xidfields); ++i) {
int offset, rc;
if (!(mask & xidfields[i].mask))

View File

@ -571,8 +571,6 @@ static const int offsets[] = {
offsetof(ColormapRec, devPrivates), /* RT_COLORMAP */
};
#define NUM_OFFSETS (sizeof (offsets) / sizeof (offsets[0]))
int
dixLookupPrivateOffset(RESTYPE type)
{
@ -587,7 +585,7 @@ dixLookupPrivateOffset(RESTYPE type)
return offsets[RT_PIXMAP & TypeMask];
}
type = type & TypeMask;
if (type < NUM_OFFSETS)
if (type < ARRAY_SIZE(offsets))
return offsets[type];
return -1;
}

View File

@ -562,10 +562,6 @@
(c)[1] = (float)y; \
} while(0)
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif
#define ALIGN(i,m) (((i) + (m) - 1) & ~((m) - 1))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))

View File

@ -66,8 +66,6 @@ KdDepths kdDepths[] = {
{32, 32}
};
#define NUM_KD_DEPTHS (sizeof (kdDepths) / sizeof (kdDepths[0]))
#define KD_DEFAULT_BUTTONS 5
DevPrivateKeyRec kdScreenPrivateKeyRec;
@ -886,7 +884,7 @@ KdSetPixmapFormats(ScreenInfo * pScreenInfo)
/*
* Fill in additional formats
*/
for (i = 0; i < NUM_KD_DEPTHS; i++)
for (i = 0; i < ARRAY_SIZE(kdDepths); i++)
if (!depthToBpp[kdDepths[i].depth])
depthToBpp[kdDepths[i].depth] = kdDepths[i].bpp;

View File

@ -89,5 +89,5 @@ BEGIN {
END {
print "};"
printf "const int xf86NumDefaultModes = sizeof(xf86DefaultModes) / sizeof(DisplayModeRec);"
printf "const int xf86NumDefaultModes = ARRAY_SIZE(xf86DefaultModes);"
}

View File

@ -206,7 +206,7 @@ configureScreenSection(int screennum)
XNFasprintf(&tmp, "Card%d", screennum);
ptr->scrn_device_str = tmp;
for (i = 0; i < sizeof(depths) / sizeof(depths[0]); i++) {
for (i = 0; i < ARRAY_SIZE(depths); i++) {
XF86ConfDisplayPtr conf_display;
conf_display = calloc(1, sizeof(XF86ConfDisplayRec));

View File

@ -477,7 +477,7 @@ xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep,
M_T_DRIVER,
0
};
const int ntypes = sizeof(types) / sizeof(int);
const int ntypes = ARRAY_SIZE(types);
strategy &= ~(LOOKUP_CLKDIV2 | LOOKUP_OPTIONAL_TOLERANCES);
@ -1853,7 +1853,7 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
M_T_DRIVER,
0
};
const int ntypes = sizeof(types) / sizeof(int);
const int ntypes = ARRAY_SIZE(types);
int n;
/*

View File

@ -1633,7 +1633,7 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
pScreen->SetWindowPixmap = DRI2SetWindowPixmap;
xf86DrvMsg(pScreen->myNum, X_INFO, "[DRI2] Setup complete\n");
for (i = 0; i < sizeof(driverTypeNames) / sizeof(driverTypeNames[0]); i++) {
for (i = 0; i < ARRAY_SIZE(driverTypeNames); i++) {
if (i < ds->numDrivers && ds->driverNames[i]) {
xf86DrvMsg(pScreen->myNum, X_INFO, "[DRI2] %s driver: %s\n",
driverTypeNames[i], ds->driverNames[i]);

View File

@ -1688,7 +1688,7 @@ drmmode_create_name(ScrnInfoPtr pScrn, drmModeConnectorPtr koutput, char *name,
return;
fallback:
if (koutput->connector_type >= MS_ARRAY_SIZE(output_names))
if (koutput->connector_type >= ARRAY_SIZE(output_names))
snprintf(name, 32, "Unknown%d-%d", koutput->connector_type, koutput->connector_type_id);
else if (pScrn->is_gpu)
snprintf(name, 32, "%s-%d-%d", output_names[koutput->connector_type], pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1, koutput->connector_type_id);

View File

@ -203,6 +203,4 @@ void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
#define DRM_CAP_DUMB_PREFER_SHADOW 4
#endif
#define MS_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
#endif

View File

@ -50,6 +50,7 @@
#include <xorg-config.h>
#endif
#include "dix.h"
#include "os.h"
#include "loaderProcs.h"
#include "xf86Module.h"
@ -225,7 +226,7 @@ InitPatterns(const char **patternlist)
if (patternlist) {
for (i = 0, s = patternlist; *s; i++, s++)
if (*s == DEFAULT_LIST)
i += sizeof(stdPatterns) / sizeof(stdPatterns[0]) - 1 - 1;
i += ARRAY_SIZE(stdPatterns) - 1 - 1;
patterns = xallocarray(i + 1, sizeof(PatternRec));
if (!patterns) {
return NULL;

View File

@ -430,7 +430,7 @@ FindDMTMode(int hsize, int vsize, int refresh, Bool rb)
int i;
const DisplayModeRec *ret;
for (i = 0; i < sizeof(DMTModes) / sizeof(DisplayModeRec); i++) {
for (i = 0; i < ARRAY_SIZE(DMTModes); i++) {
ret = &DMTModes[i];
if (!rb && xf86ModeIsReduced(ret))
@ -527,11 +527,9 @@ DDCModeDoInterlaceQuirks(DisplayModePtr mode)
{1440, 576},
{2880, 576},
};
static const int n_modes =
sizeof(cea_interlaced) / sizeof(cea_interlaced[0]);
int i;
for (i = 0; i < n_modes; i++) {
for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
if ((mode->HDisplay == cea_interlaced[i].w) &&
(mode->VDisplay == cea_interlaced[i].h / 2)) {
mode->VDisplay *= 2;

View File

@ -37,14 +37,12 @@ static struct {
#endif
};
#define numApmEvents (sizeof(bsdToXF86Array) / sizeof(bsdToXF86Array[0]))
static pmEvent
bsdToXF86(int type)
{
int i;
for (i = 0; i < numApmEvents; i++) {
for (i = 0; i < ARRAY_SIZE(bsdToXF86Array); i++) {
if (type == bsdToXF86Array[i].apmBsd) {
return bsdToXF86Array[i].xf86;
}

View File

@ -192,7 +192,7 @@ xf86OpenConsole()
/* Check that a supported console driver was found */
if (fd < 0) {
char cons_drivers[80] = { 0, };
for (i = 0; i < sizeof(supported_drivers) / sizeof(char *); i++) {
for (i = 0; i < ARRAY_SIZE(supported_drivers); i++) {
if (i) {
strcat(cons_drivers, ", ");
}

View File

@ -70,14 +70,12 @@ static struct {
#endif
};
#define numApmEvents (sizeof(bsdToXF86Array) / sizeof(bsdToXF86Array[0]))
static pmEvent
bsdToXF86(int type)
{
int i;
for (i = 0; i < numApmEvents; i++) {
for (i = 0; i < ARRAY_SIZE(bsdToXF86Array); i++) {
if (type == bsdToXF86Array[i].apmBsd) {
return bsdToXF86Array[i].xf86;
}

View File

@ -62,8 +62,6 @@ static struct {
#endif
};
#define numApmEvents (sizeof(LinuxToXF86) / sizeof(LinuxToXF86[0]))
/*
* APM is still under construction.
* I'm not sure if the places where I initialize/deinitialize
@ -84,12 +82,12 @@ lnxPMGetEventFromOs(int fd, pmEvent * events, int num)
if (n > num)
n = num;
for (i = 0; i < n; i++) {
for (j = 0; j < numApmEvents; j++)
for (j = 0; j < ARRAY_SIZE(LinuxToXF86); j++)
if (LinuxToXF86[j].apmLinux == linuxEvents[i]) {
events[i] = LinuxToXF86[j].xf86;
break;
}
if (j == numApmEvents)
if (j == ARRAY_SIZE(LinuxToXF86))
events[i] = XF86_APM_UNKNOWN;
}
return n;

View File

@ -485,7 +485,7 @@ static struct states {
#endif
};
static int numStates = sizeof(modemStates) / sizeof(modemStates[0]);
static int numStates = ARRAY_SIZE(modemStates);
static int
xf2osState(int state)

View File

@ -113,14 +113,12 @@ static struct {
#endif
};
#define numApmEvents (sizeof(sunToXF86Array) / sizeof(sunToXF86Array[0]))
static pmEvent
sunToXF86(int type)
{
int i;
for (i = 0; i < numApmEvents; i++) {
for (i = 0; i < ARRAY_SIZE(sunToXF86Array); i++) {
if (type == sunToXF86Array[i].apmBsd) {
return sunToXF86Array[i].xf86;
}

View File

@ -162,7 +162,6 @@ static PixmapFormatRec formats[] = {
{ 24, 32, BITMAP_SCANLINE_PAD },
{ 32, 32, BITMAP_SCANLINE_PAD }
};
const int NUMFORMATS = sizeof(formats) / sizeof(formats[0]);
void
DarwinPrintBanner(void)
@ -659,8 +658,8 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
// List how we want common pixmap formats to be padded
pScreenInfo->numPixmapFormats = NUMFORMATS;
for (i = 0; i < NUMFORMATS; i++)
pScreenInfo->numPixmapFormats = ARRAY_SIZE(formats);
for (i = 0; i < ARRAY_SIZE(formats); i++)
pScreenInfo->formats[i] = formats[i];
// Discover screens and do mode specific initialization

View File

@ -832,7 +832,7 @@ long
keysym2ucs(int keysym)
{
int min = 0;
int max = sizeof(keysymtab) / sizeof(struct codepair) - 1;
int max = ARRAY_SIZE(keysymtab) - 1;
int mid;
/* first check for Latin-1 characters (1:1 mapping) */
@ -875,7 +875,7 @@ ucs2keysym(long ucs)
static struct codepair *reverse_keysymtab;
int min = 0;
int max = sizeof(keysymtab) / sizeof(struct codepair) - 1;
int max = ARRAY_SIZE(keysymtab) - 1;
int mid;
if (reverse_keysymtab == NULL) {
@ -883,7 +883,7 @@ ucs2keysym(long ucs)
memcpy(reverse_keysymtab, keysymtab, sizeof(keysymtab));
qsort(reverse_keysymtab,
sizeof(keysymtab) / sizeof(struct codepair),
ARRAY_SIZE(keysymtab),
sizeof(struct codepair),
reverse_compare);
}

View File

@ -30,6 +30,8 @@
#ifndef KEYSYM2UCS_H
#define KEYSYM2UCS_H 1
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
extern long
keysym2ucs(int keysym);
extern int

View File

@ -790,7 +790,7 @@ make_dead_key(KeySym in)
{
int i;
for (i = 0; i < sizeof(dead_keys) / sizeof(dead_keys[0]); i++)
for (i = 0; i < ARRAY_SIZE(dead_keys); i++)
if (dead_keys[i].normal == in) return dead_keys[i].dead;
return in;
@ -975,7 +975,7 @@ QuartzReadSystemKeymap(darwinKeyboardInfo *info)
#if HACK_MISSING
/* Fix up some things that are normally missing.. */
for (i = 0; i < sizeof(known_keys) / sizeof(known_keys[0]); i++) {
for (i = 0; i < ARRAY_SIZE(known_keys); i++) {
k = info->keyMap + known_keys[i].keycode * GLYPHS_PER_KEY;
if (k[0] == NoSymbol && k[1] == NoSymbol
@ -987,8 +987,7 @@ QuartzReadSystemKeymap(darwinKeyboardInfo *info)
#if HACK_KEYPAD
/* And some more things. We find the right symbols for the numeric
keypad, but not the KP_ keysyms. So try to convert known keycodes. */
for (i = 0; i < sizeof(known_numeric_keys) / sizeof(known_numeric_keys[0]);
i++) {
for (i = 0; i < ARRAY_SIZE(known_numeric_keys); i++) {
k = info->keyMap + known_numeric_keys[i].keycode * GLYPHS_PER_KEY;
if (k[0] == known_numeric_keys[i].normal)
@ -997,8 +996,7 @@ QuartzReadSystemKeymap(darwinKeyboardInfo *info)
#endif
#if HACK_BLACKLIST
for (i = 0; i < sizeof(keycode_blacklist) / sizeof(keycode_blacklist[0]);
i++) {
for (i = 0; i < ARRAY_SIZE(keycode_blacklist); i++) {
k = info->keyMap + keycode_blacklist[i] * GLYPHS_PER_KEY;
k[0] = k[1] = k[2] = k[3] = NoSymbol;
}

View File

@ -37,6 +37,8 @@
#include <stdlib.h>
#include <assert.h>
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
struct x_hash_table_struct {
unsigned int bucket_index;
unsigned int total_keys;
@ -65,8 +67,6 @@ static const unsigned int bucket_sizes[] = {
1610612741
};
#define N_BUCKET_SIZES (sizeof(bucket_sizes) / sizeof(bucket_sizes[0]))
static inline unsigned int
hash_table_total_buckets(x_hash_table *h)
{
@ -110,7 +110,7 @@ hash_table_split(x_hash_table *h)
size_t b;
int i;
if (h->bucket_index == N_BUCKET_SIZES - 1)
if (h->bucket_index == ARRAY_SIZE(bucket_sizes) - 1)
return;
old_size = hash_table_total_buckets(h);

View File

@ -111,8 +111,6 @@ static PixmapFormatRec g_PixmapFormats[] = {
{32, 32, BITMAP_SCANLINE_PAD}
};
const int NUMFORMATS = sizeof(g_PixmapFormats) / sizeof(g_PixmapFormats[0]);
static const ExtensionModule xwinExtensions[] = {
#ifdef GLXEXT
{ GlxExtensionInit, "GLX", &noGlxExtension },
@ -932,10 +930,10 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char *argv[])
pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
pScreenInfo->numPixmapFormats = NUMFORMATS;
pScreenInfo->numPixmapFormats = ARRAY_SIZE(g_PixmapFormats);
/* Describe how we want common pixmap formats padded */
for (i = 0; i < NUMFORMATS; i++) {
for (i = 0; i < ARRAY_SIZE(g_PixmapFormats); i++) {
pScreenInfo->formats[i] = g_PixmapFormats[i];
}

View File

@ -88,8 +88,6 @@
#include <winglobals.h>
#include <indirect.h>
#define NUM_ELEMENTS(x) (sizeof(x)/ sizeof(x[1]))
/* Not yet in w32api */
#ifndef PFD_SUPPORT_DIRECTDRAW
#define PFD_SUPPORT_DIRECTDRAW 0x00002000
@ -1639,7 +1637,7 @@ fbConfigToPixelFormat(__GLXconfig * mode, PIXELFORMATDESCRIPTOR * pfdret,
return 0;
}
#define SET_ATTR_VALUE(attr, value) { attribList[i++] = attr; attribList[i++] = value; assert(i < NUM_ELEMENTS(attribList)); }
#define SET_ATTR_VALUE(attr, value) { attribList[i++] = attr; attribList[i++] = value; assert(i < ARRAY_SIZE(attribList)); }
static int
fbConfigToPixelFormatIndex(HDC hdc, __GLXconfig * mode,
@ -2018,7 +2016,7 @@ glxWinCreateConfigsExt(HDC hdc, glxWinScreen * screen)
memset(result, 0, sizeof(GLXWinConfig) * numConfigs);
n = 0;
#define ADD_ATTR(a) { attrs[num_attrs++] = a; assert(num_attrs < NUM_ELEMENTS(attrs)); }
#define ADD_ATTR(a) { attrs[num_attrs++] = a; assert(num_attrs < ARRAY_SIZE(attrs)); }
ADD_ATTR(WGL_DRAW_TO_WINDOW_ARB);
ADD_ATTR(WGL_DRAW_TO_BITMAP_ARB);

View File

@ -46,6 +46,8 @@
#define WM_WM_REINIT (WM_USER + 1)
#define WM_WM_QUIT (WM_USER + 2)
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
/*
* References to external symbols
*/

View File

@ -529,7 +529,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
int i,j;
for (i = 0 ; data.targetList[i] != 0; i++)
{
for (j = 0; j < sizeof(target_priority_table)/sizeof(struct target_priority); j ++)
for (j = 0; j < ARRAY_SIZE(target_priority_table); j ++)
{
if ((data.targetList[i] == target_priority_table[j].target) &&
(target_priority_table[j].priority < best_priority))

View File

@ -267,8 +267,7 @@ winClipboardFlushXEvents(HWND hwnd,
32,
PropModeReplace,
(unsigned char *) atomTargetArr,
(sizeof(atomTargetArr)
/ sizeof(atomTargetArr[0])));
ARRAY_SIZE(atomTargetArr));
if (iReturn == BadAlloc
|| iReturn == BadAtom
|| iReturn == BadMatch

View File

@ -1517,7 +1517,7 @@ winInitMultiWindowWM(WMInfoPtr pWMInfo, WMProcArgPtr pProcArg)
};
xcb_ewmh_set_supported(&pWMInfo->ewmh, pProcArg->dwScreen,
sizeof(supported)/sizeof(xcb_atom_t), supported);
ARRAY_SIZE(supported), supported);
}
else {
ErrorF("winInitMultiWindowWM - xcb_ewmh_init_atoms() failed\n");

View File

@ -90,8 +90,7 @@ static struct protocol protocols[] = {
#endif
};
#define NUM_AUTHORIZATION (sizeof (protocols) /\
sizeof (struct protocol))
#define NUM_AUTHORIZATION ARRAY_SIZE(protocols)
/*
* Initialize all classes of authorization by reading the

View File

@ -49,6 +49,7 @@ SOFTWARE.
#endif
#include <X11/keysym.h>
#include "dix.h"
#include "os.h"
typedef struct _builtinColor {
@ -1628,8 +1629,6 @@ static const BuiltinColor BuiltinColors[] = {
{154, 205, 50, 7602}, /* YellowGreen */
};
#define NUM_BUILTIN_COLORS (sizeof (BuiltinColors) / sizeof (BuiltinColors[0]))
Bool
OsLookupColor(int screen,
char *name,
@ -1642,7 +1641,7 @@ OsLookupColor(int screen,
int r;
low = 0;
high = NUM_BUILTIN_COLORS - 1;
high = ARRAY_SIZE(BuiltinColors) - 1;
while (high >= low) {
mid = (low + high) / 2;
c = &BuiltinColors[mid];

View File

@ -78,7 +78,7 @@ static GlyphHashSetRec glyphHashSets[] = {
{536870912, 590559793, 590559791}
};
#define NGLYPHHASHSETS (sizeof(glyphHashSets)/sizeof(glyphHashSets[0]))
#define NGLYPHHASHSETS ARRAY_SIZE(glyphHashSets)
static GlyphHashRec globalGlyphs[GlyphFormatNum];

View File

@ -1427,7 +1427,7 @@ include_bit_test_macros(void)
uint8_t mask[9] = { 0 };
int i;
for (i = 0; i < sizeof(mask) / sizeof(mask[0]); i++) {
for (i = 0; i < ARRAY_SIZE(mask); i++) {
assert(BitIsOn(mask, i) == 0);
SetBit(mask, i);
assert(BitIsOn(mask, i) == 1);

View File

@ -145,13 +145,13 @@ number_formatting(void)
-0x7FFFFFFFFFFFFFFF, /* Maximum 64-bit signed number */
} ;
for (i = 0; i < sizeof(unsigned_tests) / sizeof(unsigned_tests[0]); i++)
for (i = 0; i < ARRAY_SIZE(unsigned_tests); i++)
assert(check_number_format_test(unsigned_tests[i]));
for (i = 0; i < sizeof(signed_tests) / sizeof(signed_tests[0]); i++)
for (i = 0; i < ARRAY_SIZE(signed_tests); i++)
assert(check_signed_number_format_test(signed_tests[i]));
for (i = 0; i < sizeof(float_tests) / sizeof(float_tests[0]); i++)
for (i = 0; i < ARRAY_SIZE(float_tests); i++)
assert(check_float_format_test(float_tests[i]));
}
#pragma GCC diagnostic pop
@ -366,7 +366,7 @@ static void logging_format(void)
} while(ptr);
for (i = 0; i < sizeof(float_tests)/sizeof(float_tests[0]); i++) {
for (i = 0; i < ARRAY_SIZE(float_tests); i++) {
double d = float_tests[i];
char expected[30];
sprintf(expected, "(EE) %.2f\n", d);

View File

@ -3,6 +3,8 @@
#include "tests.h"
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
#define run_test(func) run_test_in_child(func, #func)
void run_test_in_child(int (*func)(void), const char *funcname);

View File

@ -581,8 +581,6 @@ static const RESTYPE CursorRestypes[] = {
RT_WINDOW, RT_PASSIVEGRAB, RT_CURSOR
};
#define NUM_CURSOR_RESTYPES (sizeof (CursorRestypes) / sizeof (CursorRestypes[0]))
static Bool
ReplaceCursorLookup(void *value, XID id, void *closure)
{
@ -645,7 +643,7 @@ ReplaceCursor(CursorPtr pCursor, TestCursorFunc testCursor, void *closure)
for (clientIndex = 0; clientIndex < currentMaxClients; clientIndex++) {
if (!clients[clientIndex])
continue;
for (resIndex = 0; resIndex < NUM_CURSOR_RESTYPES; resIndex++) {
for (resIndex = 0; resIndex < ARRAY_SIZE(CursorRestypes); resIndex++) {
rcl.type = CursorRestypes[resIndex];
/*
* This function walks the entire client resource database

View File

@ -105,8 +105,6 @@ static const int version_requests[] = {
X_XFixesDestroyPointerBarrier, /* Version 5 */
};
#define NUM_VERSION_REQUESTS (sizeof (version_requests) / sizeof (version_requests[0]))
int (*ProcXFixesVector[XFixesNumberRequests]) (ClientPtr) = {
/*************** Version 1 ******************/
ProcXFixesQueryVersion,
@ -149,7 +147,7 @@ ProcXFixesDispatch(ClientPtr client)
REQUEST(xXFixesReq);
XFixesClientPtr pXFixesClient = GetXFixesClient(client);
if (pXFixesClient->major_version >= NUM_VERSION_REQUESTS)
if (pXFixesClient->major_version >= ARRAY_SIZE(version_requests))
return BadRequest;
if (stuff->xfixesReqType > version_requests[pXFixesClient->major_version])
return BadRequest;

View File

@ -131,7 +131,7 @@ static XkbKeyTypeRec dflt_types[] = {
None, lnames_SHIFT_ALT}
};
#define num_dflt_types (sizeof(dflt_types)/sizeof(XkbKeyTypeRec))
#define num_dflt_types ARRAY_SIZE(dflt_types)
static void
initTypeNames(DPYTYPE dpy)
@ -445,7 +445,7 @@ static XkbSymInterpretRec dfltSI[69] = {
{XkbSA_SetMods, {0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}
};
#define num_dfltSI (sizeof(dfltSI)/sizeof(XkbSymInterpretRec))
#define num_dfltSI ARRAY_SIZE(dfltSI)
static XkbCompatMapRec compatMap = {
dfltSI,