diff --git a/Xext/geext.c b/Xext/geext.c index 6312f248b..0a5ca9038 100644 --- a/Xext/geext.c +++ b/Xext/geext.c @@ -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; diff --git a/Xext/saver.c b/Xext/saver.c index 45ac4d2c9..d97b236a3 100644 --- a/Xext/saver.c +++ b/Xext/saver.c @@ -1267,14 +1267,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; } @@ -1359,7 +1357,7 @@ SProcScreenSaverDispatch(ClientPtr client) { REQUEST(xReq); - if (stuff->data < NUM_REQUESTS) + if (stuff->data < ARRAY_SIZE(NormalVector)) return (*SwappedVector[stuff->data]) (client); return BadRequest; } diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c index b7a1f59f4..945005da0 100644 --- a/Xi/xiproperty.c +++ b/Xi/xiproperty.c @@ -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; } diff --git a/composite/compinit.c b/composite/compinit.c index 791fec922..2590aa46d 100644 --- a/composite/compinit.c +++ b/composite/compinit.c @@ -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; diff --git a/damageext/damageext.c b/damageext/damageext.c index 86b54eef4..f8733f44b 100644 --- a/damageext/damageext.c +++ b/damageext/damageext.c @@ -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; diff --git a/dix/eventconvert.c b/dix/eventconvert.c index f7ecdba77..4a07b6b6f 100644 --- a/dix/eventconvert.c +++ b/dix/eventconvert.c @@ -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 */ diff --git a/dix/gc.c b/dix/gc.c index 78f3be29d..b3817156e 100644 --- a/dix/gc.c +++ b/dix/gc.c @@ -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)) diff --git a/dix/privates.c b/dix/privates.c index 478f52cbe..d686f8910 100644 --- a/dix/privates.c +++ b/dix/privates.c @@ -572,8 +572,6 @@ static const int offsets[] = { offsetof(ColormapRec, devPrivates), /* RT_COLORMAP */ }; -#define NUM_OFFSETS (sizeof (offsets) / sizeof (offsets[0])) - int dixLookupPrivateOffset(RESTYPE type) { @@ -588,7 +586,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; } diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h index a35917c37..48550f77f 100644 --- a/glamor/glamor_utils.h +++ b/glamor/glamor_utils.h @@ -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)) diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c index f02d8262b..afd288d6d 100644 --- a/hw/kdrive/src/kdrive.c +++ b/hw/kdrive/src/kdrive.c @@ -66,8 +66,6 @@ KdDepths kdDepths[] = { {32, 32} }; -#define NUM_KD_DEPTHS (sizeof (kdDepths) / sizeof (kdDepths[0])) - #define KD_DEFAULT_BUTTONS 5 DevPrivateKeyRec kdScreenPrivateKeyRec; @@ -1065,7 +1063,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; diff --git a/hw/xfree86/common/modeline2c.awk b/hw/xfree86/common/modeline2c.awk index 038e7e935..3c9f602d1 100644 --- a/hw/xfree86/common/modeline2c.awk +++ b/hw/xfree86/common/modeline2c.awk @@ -89,5 +89,5 @@ BEGIN { END { print "};" - printf "const int xf86NumDefaultModes = sizeof(xf86DefaultModes) / sizeof(DisplayModeRec);" + printf "const int xf86NumDefaultModes = ARRAY_SIZE(xf86DefaultModes);" } diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 59d275ea3..71b93a74d 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -205,7 +205,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)); diff --git a/hw/xfree86/common/xf86Mode.c b/hw/xfree86/common/xf86Mode.c index 3f446ae3b..d79e9aed9 100644 --- a/hw/xfree86/common/xf86Mode.c +++ b/hw/xfree86/common/xf86Mode.c @@ -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); @@ -1874,7 +1874,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; /* diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c index 2165603d9..4856b436d 100644 --- a/hw/xfree86/dri2/dri2.c +++ b/hw/xfree86/dri2/dri2.c @@ -1629,7 +1629,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]); diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 45d5e9091..2c02ea8a8 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -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); diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h index 50976b849..4858a5ca9 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.h +++ b/hw/xfree86/drivers/modesetting/drmmode_display.h @@ -205,6 +205,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 diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c index 8bf6836d6..a5975305a 100644 --- a/hw/xfree86/loader/loadmod.c +++ b/hw/xfree86/loader/loadmod.c @@ -50,6 +50,7 @@ #include #endif +#include "dix.h" #include "os.h" /* For stat() and related stuff */ #define NO_OSLIB_PROTOTYPES @@ -242,7 +243,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; diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c index f903496f5..2035f0cba 100644 --- a/hw/xfree86/modes/xf86EdidModes.c +++ b/hw/xfree86/modes/xf86EdidModes.c @@ -434,7 +434,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)) @@ -531,11 +531,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; diff --git a/hw/xfree86/os-support/bsd/bsd_apm.c b/hw/xfree86/os-support/bsd/bsd_apm.c index 60a19d79a..dab0a9a7d 100644 --- a/hw/xfree86/os-support/bsd/bsd_apm.c +++ b/hw/xfree86/os-support/bsd/bsd_apm.c @@ -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; } diff --git a/hw/xfree86/os-support/bsd/bsd_init.c b/hw/xfree86/os-support/bsd/bsd_init.c index 0d5d3c87c..75a719fc2 100644 --- a/hw/xfree86/os-support/bsd/bsd_init.c +++ b/hw/xfree86/os-support/bsd/bsd_init.c @@ -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, ", "); } diff --git a/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c b/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c index 1756612b4..b046a1aa8 100644 --- a/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c +++ b/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c @@ -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; } diff --git a/hw/xfree86/os-support/linux/lnx_apm.c b/hw/xfree86/os-support/linux/lnx_apm.c index 621691997..29c363360 100644 --- a/hw/xfree86/os-support/linux/lnx_apm.c +++ b/hw/xfree86/os-support/linux/lnx_apm.c @@ -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; diff --git a/hw/xfree86/os-support/shared/posix_tty.c b/hw/xfree86/os-support/shared/posix_tty.c index a795ae19d..6768d290b 100644 --- a/hw/xfree86/os-support/shared/posix_tty.c +++ b/hw/xfree86/os-support/shared/posix_tty.c @@ -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) diff --git a/hw/xfree86/os-support/solaris/sun_apm.c b/hw/xfree86/os-support/solaris/sun_apm.c index 4d4dbc105..dbdc4b677 100644 --- a/hw/xfree86/os-support/solaris/sun_apm.c +++ b/hw/xfree86/os-support/solaris/sun_apm.c @@ -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; } diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c index 36c149cba..71a65f3ce 100644 --- a/hw/xquartz/darwin.c +++ b/hw/xquartz/darwin.c @@ -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 diff --git a/hw/xquartz/keysym2ucs.c b/hw/xquartz/keysym2ucs.c index 934b57756..12da19d67 100644 --- a/hw/xquartz/keysym2ucs.c +++ b/hw/xquartz/keysym2ucs.c @@ -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); } diff --git a/hw/xquartz/keysym2ucs.h b/hw/xquartz/keysym2ucs.h index 01af0371d..aedbf43bf 100644 --- a/hw/xquartz/keysym2ucs.h +++ b/hw/xquartz/keysym2ucs.h @@ -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 diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c index b16b7b34f..1399da7b6 100644 --- a/hw/xquartz/quartzKeyboard.c +++ b/hw/xquartz/quartzKeyboard.c @@ -748,7 +748,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; @@ -845,7 +845,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 @@ -857,8 +857,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) @@ -867,8 +866,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; } diff --git a/hw/xquartz/xpr/x-hash.c b/hw/xquartz/xpr/x-hash.c index 26e079ff0..087656d9b 100644 --- a/hw/xquartz/xpr/x-hash.c +++ b/hw/xquartz/xpr/x-hash.c @@ -37,6 +37,8 @@ #include #include +#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); diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c index edd526647..5b363d570 100644 --- a/hw/xwin/InitOutput.c +++ b/hw/xwin/InitOutput.c @@ -113,8 +113,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 }, @@ -944,10 +942,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]; } diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c index 239327ed4..32ade8150 100644 --- a/hw/xwin/glx/indirect.c +++ b/hw/xwin/glx/indirect.c @@ -88,8 +88,6 @@ #include #include -#define NUM_ELEMENTS(x) (sizeof(x)/ sizeof(x[1])) - /* Not yet in w32api */ #ifndef PFD_SUPPORT_DIRECTDRAW #define PFD_SUPPORT_DIRECTDRAW 0x00002000 @@ -1643,7 +1641,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, @@ -2022,7 +2020,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); diff --git a/hw/xwin/winclipboard/internal.h b/hw/xwin/winclipboard/internal.h index d0d8fbda1..2e6b22db3 100644 --- a/hw/xwin/winclipboard/internal.h +++ b/hw/xwin/winclipboard/internal.h @@ -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 */ diff --git a/hw/xwin/winclipboard/wndproc.c b/hw/xwin/winclipboard/wndproc.c index d289f7755..c8d0064bd 100644 --- a/hw/xwin/winclipboard/wndproc.c +++ b/hw/xwin/winclipboard/wndproc.c @@ -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)) diff --git a/hw/xwin/winclipboard/xevents.c b/hw/xwin/winclipboard/xevents.c index aee6c86a2..d4ea97fc3 100644 --- a/hw/xwin/winclipboard/xevents.c +++ b/hw/xwin/winclipboard/xevents.c @@ -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 diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c index df7e6d3d5..d073969da 100644 --- a/hw/xwin/winmultiwindowwm.c +++ b/hw/xwin/winmultiwindowwm.c @@ -1515,7 +1515,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"); diff --git a/os/auth.c b/os/auth.c index c7b333ca2..0e96f7d62 100644 --- a/os/auth.c +++ b/os/auth.c @@ -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 diff --git a/os/oscolor.c b/os/oscolor.c index 017aab1f2..af83c6ada 100644 --- a/os/oscolor.c +++ b/os/oscolor.c @@ -49,6 +49,7 @@ SOFTWARE. #endif #include +#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]; diff --git a/render/glyph.c b/render/glyph.c index ea865af58..f3ed9cf4c 100644 --- a/render/glyph.c +++ b/render/glyph.c @@ -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]; diff --git a/test/input.c b/test/input.c index 92dd8910c..5846aa568 100644 --- a/test/input.c +++ b/test/input.c @@ -43,6 +43,8 @@ #include "mi.h" #include "assert.h" +#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) + /** * Init a device with axes. * Verify values set on the device. @@ -1425,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); diff --git a/test/signal-logging.c b/test/signal-logging.c index 1af6316de..67ae73e70 100644 --- a/test/signal-logging.c +++ b/test/signal-logging.c @@ -30,6 +30,8 @@ #include "assert.h" #include "misc.h" +#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) + struct number_format_test { uint64_t number; char string[21]; @@ -143,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 @@ -364,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); diff --git a/xfixes/cursor.c b/xfixes/cursor.c index a150f450b..d19f391c8 100644 --- a/xfixes/cursor.c +++ b/xfixes/cursor.c @@ -595,8 +595,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) { @@ -659,7 +657,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 diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c index 8b45c5349..696543b32 100644 --- a/xfixes/xfixes.c +++ b/xfixes/xfixes.c @@ -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; diff --git a/xkb/xkbDflts.h b/xkb/xkbDflts.h index 994726c0f..b02dff9de 100644 --- a/xkb/xkbDflts.h +++ b/xkb/xkbDflts.h @@ -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,