mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-18 20:10:29 +01:00
Changed formula for getting the number of elements in a static array
When using the formula [sizeof(array) / sizeof( x )] to get the number of element in a static array, it is better to use array[0] for 'x' instead of the base type of array: - in case the base type would change someday; - if the compiler were deciding to insert padding somewhere
This commit is contained in:
committed by
Carlos R. Mafra
parent
e17a197bc4
commit
7f6699ffca
@@ -428,7 +428,7 @@ static void addSizeToTypeface(Typeface * face, int size)
|
||||
if (size == 0) {
|
||||
int j;
|
||||
|
||||
for (j = 0; j < sizeof(scalableFontSizes) / sizeof(int); j++) {
|
||||
for (j = 0; j < sizeof(scalableFontSizes) / sizeof(scalableFontSizes[0]); j++) {
|
||||
size = scalableFontSizes[j];
|
||||
|
||||
if (!WMCountInArray(face->sizes, (void *)(uintptr_t) size)) {
|
||||
|
||||
@@ -552,7 +552,7 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
|
||||
"_NET_WM_ICON_NAME",
|
||||
"_NET_WM_ICON",
|
||||
};
|
||||
Atom atoms[sizeof(atomNames) / sizeof(char *)];
|
||||
Atom atoms[sizeof(atomNames) / sizeof(atomNames[0])];
|
||||
int i;
|
||||
|
||||
if (!initialized) {
|
||||
@@ -803,9 +803,9 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
|
||||
}
|
||||
|
||||
#ifdef HAVE_XINTERNATOMS
|
||||
XInternAtoms(display, atomNames, sizeof(atomNames) / sizeof(char *), False, atoms);
|
||||
XInternAtoms(display, atomNames, sizeof(atomNames) / sizeof(atomNames[0]), False, atoms);
|
||||
#else
|
||||
for (i = 0; i < sizeof(atomNames) / sizeof(char *); i++) {
|
||||
for (i = 0; i < sizeof(atomNames) / sizeof(atomNames[0]); i++) {
|
||||
atoms[i] = XInternAtom(display, atomNames[i], False);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1102,7 +1102,7 @@ static void previewClick(XEvent * event, void *clientData)
|
||||
|
||||
switch (panel->oldTabItem) {
|
||||
case 0:
|
||||
for (i = 0; i < sizeof(previewPositions) / sizeof(WMRect); i++) {
|
||||
for (i = 0; i < sizeof(previewPositions) / sizeof(previewPositions[0]); i++) {
|
||||
if (event->xbutton.x >= previewPositions[i].pos.x
|
||||
&& event->xbutton.y >= previewPositions[i].pos.y
|
||||
&& event->xbutton.x < previewPositions[i].pos.x
|
||||
|
||||
@@ -608,13 +608,13 @@ static void createPanel(Panel * p)
|
||||
WMResizeWidget(panel->wheelP, 135, 20);
|
||||
WMMoveWidget(panel->wheelP, 95, 129);
|
||||
|
||||
for (i = 0; i < sizeof(buttonActions) / sizeof(char *); i++) {
|
||||
for (i = 0; i < sizeof(buttonActions) / sizeof(buttonActions[0]); i++) {
|
||||
WMAddPopUpButtonItem(panel->button1P, buttonActions[i]);
|
||||
WMAddPopUpButtonItem(panel->button2P, buttonActions[i]);
|
||||
WMAddPopUpButtonItem(panel->button3P, buttonActions[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(wheelActions) / sizeof(char *); i++) {
|
||||
for (i = 0; i < sizeof(wheelActions) / sizeof(wheelActions[0]); i++) {
|
||||
WMAddPopUpButtonItem(panel->wheelP, wheelActions[i]);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ static void showData(_Panel * panel)
|
||||
str = "center";
|
||||
|
||||
idx = 1; /* center */
|
||||
for (i = 0; i < sizeof(WSNamePositions) / sizeof(char *); i++) {
|
||||
for (i = 0; i < sizeof(WSNamePositions) / sizeof(WSNamePositions[0]); i++) {
|
||||
if (strcasecmp(WSNamePositions[i], str) == 0) {
|
||||
idx = i;
|
||||
break;
|
||||
|
||||
@@ -760,7 +760,7 @@ static void initDefaults()
|
||||
|
||||
WMPLSetCaseSensitive(False);
|
||||
|
||||
for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
|
||||
for (i = 0; i < sizeof(optionList) / sizeof(optionList[0]); i++) {
|
||||
entry = &optionList[i];
|
||||
|
||||
entry->plkey = WMCreatePLString(entry->key);
|
||||
@@ -770,7 +770,7 @@ static void initDefaults()
|
||||
entry->plvalue = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
|
||||
for (i = 0; i < sizeof(staticOptionList) / sizeof(staticOptionList[0]); i++) {
|
||||
entry = &staticOptionList[i];
|
||||
|
||||
entry->plkey = WMCreatePLString(entry->key);
|
||||
@@ -925,7 +925,7 @@ void wReadStaticDefaults(WMPropList * dict)
|
||||
unsigned int i;
|
||||
void *tdata;
|
||||
|
||||
for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
|
||||
for (i = 0; i < sizeof(staticOptionList) / sizeof(staticOptionList[0]); i++) {
|
||||
entry = &staticOptionList[i];
|
||||
|
||||
if (dict)
|
||||
@@ -1079,7 +1079,7 @@ void wReadDefaults(WScreen * scr, WMPropList * new_dict)
|
||||
|
||||
needs_refresh = 0;
|
||||
|
||||
for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
|
||||
for (i = 0; i < sizeof(optionList) / sizeof(optionList[0]); i++) {
|
||||
entry = &optionList[i];
|
||||
|
||||
if (new_dict)
|
||||
|
||||
@@ -482,7 +482,7 @@ void StartUp(Bool defaultScreenOnly)
|
||||
#ifdef HAVE_XRANDR
|
||||
int dummy;
|
||||
#endif
|
||||
Atom atom[sizeof(atomNames) / sizeof(char *)];
|
||||
Atom atom[sizeof(atomNames) / sizeof(atomNames[0])];
|
||||
|
||||
/*
|
||||
* Ignore CapsLock in modifiers
|
||||
@@ -505,12 +505,12 @@ void StartUp(Bool defaultScreenOnly)
|
||||
/* _XA_VERSION = XInternAtom(dpy, "VERSION", False); */
|
||||
|
||||
#ifdef HAVE_XINTERNATOMS
|
||||
XInternAtoms(dpy, atomNames, sizeof(atomNames) / sizeof(char *), False, atom);
|
||||
XInternAtoms(dpy, atomNames, sizeof(atomNames) / sizeof(atomNames[0]), False, atom);
|
||||
#else
|
||||
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < sizeof(atomNames) / sizeof(char *); i++)
|
||||
for (i = 0; i < sizeof(atomNames) / sizeof(atomNames[0]); i++)
|
||||
atom[i] = XInternAtom(dpy, atomNames[i], False);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -202,7 +202,7 @@ static atomitem_t atomNames[] = {
|
||||
{"UTF8_STRING", &utf8_string},
|
||||
};
|
||||
|
||||
#define atomNr (sizeof(atomNames)/sizeof(atomitem_t))
|
||||
#define atomNr (sizeof(atomNames)/sizeof(atomNames[0]))
|
||||
|
||||
#define _NET_WM_STATE_REMOVE 0
|
||||
#define _NET_WM_STATE_ADD 1
|
||||
|
||||
@@ -168,7 +168,7 @@ void FormatXError(Display * dpy, XErrorEvent * error, char *buffer, int size)
|
||||
if (i > size - 100)
|
||||
return;
|
||||
buffer += i;
|
||||
if (error->request_code >= sizeof(requestCodes) / sizeof(char *)) {
|
||||
if (error->request_code >= sizeof(requestCodes) / sizeof(requestCodes[0])) {
|
||||
sprintf(buffer, "\n Request code: %i\n", error->request_code);
|
||||
} else {
|
||||
sprintf(buffer, "\n Request code: %i %s\n", error->request_code,
|
||||
|
||||
@@ -105,7 +105,7 @@ static char *mapWeightToName(str * weight)
|
||||
if (weight->len == 0)
|
||||
return "";
|
||||
|
||||
for (i = 0; i < sizeof(normalNames) / sizeof(char *); i++) {
|
||||
for (i = 0; i < sizeof(normalNames) / sizeof(normalNames[0]); i++) {
|
||||
if (strlen(normalNames[i]) == weight->len && strncmp(normalNames[i], weight->str, weight->len)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user