1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-21 21:38:00 +01:00

wmaker: converted macro 'SAME' into a static function

There are some risks associated with the way arguments are used in macros,
and using a function also allows check on the type of arguments and leaves
more room to the compiler for making the best optimisation choice; it also
allows writing easier to read code (and thus, to maintain).

As a side effect, this should also help Coverity in avoiding false positive
bug reports (like #109605 and #109607).

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2015-04-25 12:44:29 +02:00
committed by Carlos R. Mafra
parent 6ef343ed87
commit c8ea949b1a
2 changed files with 33 additions and 6 deletions

View File

@@ -415,7 +415,19 @@ static WSavedState *getWindowState(WScreen * scr, WMPropList * win_state)
return state; return state;
} }
#define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y))) static inline int is_same(const char *x, const char *y)
{
if ((x == NULL) && (y == NULL))
return 1;
if ((x == NULL) || (y == NULL))
return 0;
if (strcmp(x, y) == 0)
return 1;
else
return 0;
}
void wSessionRestoreState(WScreen *scr) void wSessionRestoreState(WScreen *scr)
{ {
@@ -503,8 +515,10 @@ void wSessionRestoreState(WScreen *scr)
if (dock != NULL) { if (dock != NULL) {
for (j = 0; j < dock->max_icons; j++) { for (j = 0; j < dock->max_icons; j++) {
btn = dock->icon_array[j]; btn = dock->icon_array[j];
if (btn && SAME(instance, btn->wm_instance) && if (btn && is_same(instance, btn->wm_instance) &&
SAME(class, btn->wm_class) && SAME(command, btn->command) && !btn->launching) { is_same(class, btn->wm_class) &&
is_same(command, btn->command) &&
!btn->launching) {
found = 1; found = 1;
break; break;
} }

View File

@@ -2621,7 +2621,19 @@ WMagicNumber wWindowAddSavedState(const char *instance, const char *class,
return wstate; return wstate;
} }
#define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y))) static inline int is_same(const char *x, const char *y)
{
if ((x == NULL) && (y == NULL))
return 1;
if ((x == NULL) || (y == NULL))
return 0;
if (strcmp(x, y) == 0)
return 1;
else
return 0;
}
WMagicNumber wWindowGetSavedState(Window win) WMagicNumber wWindowGetSavedState(Window win)
{ {
@@ -2637,8 +2649,9 @@ WMagicNumber wWindowGetSavedState(Window win)
if (PropGetWMClass(win, &class, &instance)) { if (PropGetWMClass(win, &class, &instance)) {
while (wstate) { while (wstate) {
if (SAME(instance, wstate->instance) && if (is_same(instance, wstate->instance) &&
SAME(class, wstate->class) && SAME(command, wstate->command)) { is_same(class, wstate->class) &&
is_same(command, wstate->command)) {
break; break;
} }
wstate = wstate->next; wstate = wstate->next;