src: Fix clang-analyzer complaints

arrange.c: Highly unlikely, maybe impossible situations

backgrounds.c: False positive (I think)

dialog.c: Fix memleak/segv on realloc failure

focus.c: False positive
	ewin should never be NULL with FOCUS_EWIN_NEW

main.c: False positive
	eoptarg will always be set if argument requires option

menus.c: Fix memleak on malloc failure

session.c: Fix dead assignment

stacking.c: False positive
	Changed code is nicer though

pager.c: False positive
	ewin would never be NULL if hiwin was NULL
	But rearrange for clarity anyway

ecompmgr.c: Avoid bogus issues
This commit is contained in:
Kim Woelders 2020-01-26 09:02:41 +01:00
parent 910a27dd56
commit c839d0e14a
10 changed files with 88 additions and 54 deletions

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2019 Kim Woelders
* Copyright (C) 2004-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -396,7 +396,8 @@ ArrangeRects(const RectBox * fixed, int fixed_count, RectBox * floating,
goto done;
/* copy "fixed" rects into the sorted list */
memcpy(sorted, fixed, fixed_count * sizeof(RectBox));
if (fixed)
memcpy(sorted, fixed, fixed_count * sizeof(RectBox));
num_sorted = fixed_count;
/* go through each floating rect in order and "fit" it in */
@ -405,6 +406,9 @@ ArrangeRects(const RectBox * fixed, int fixed_count, RectBox * floating,
ArrangeMakeXYArrays(tx1, tx2, ty1, ty2, floating[i].w, floating[i].h,
sorted, num_sorted, xarray, &xsize, yarray, &ysize);
num_spaces = xsize * ysize;
if (num_spaces <= 0)
continue;
if (alloc_spaces < num_spaces)
{
unsigned char *ptr_f;
@ -427,6 +431,8 @@ ArrangeRects(const RectBox * fixed, int fixed_count, RectBox * floating,
/* create list of all "spaces" */
ArrangeFindSpaces(xarray, xsize, yarray, ysize, filled,
spaces, alloc_spaces, &num_spaces, floating + i);
if (num_spaces <= 0)
continue;
/* find the first space that fits */
k = 0;

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2019 Kim Woelders
* Copyright (C) 2004-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -1306,7 +1306,9 @@ BackgroundsCheckDups(void)
Eprintf("Remove duplicate background %s (==%s)\n", bgx->name,
bg->name);
#endif
#ifndef __clang_analyzer__
BackgroundDestroy(bgx);
#endif
}
}
}
@ -1789,6 +1791,8 @@ BGSettingsGoTo(Dialog * d, Background * bg)
return;
num = LIST_GET_COUNT(&bg_list);
if (num <= 0)
return;
i = LIST_GET_INDEX(Background, &bg_list, bg);
if (i < 0)
return;

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2018 Kim Woelders
* Copyright (C) 2004-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -1125,13 +1125,16 @@ DialogRealizeItem(Dialog * d, DItem * di)
c += dii->col_span;
if (c >= cols)
{
int *pi;
c = 0;
r++;
rows++;
row_size = EREALLOC(int, row_size, rows);
if (!row_size)
pi = EREALLOC(int, row_size, rows);
if (!pi)
goto bail_out;
row_size = pi;
row_size[rows - 1] = 0;
}

View File

@ -448,7 +448,11 @@ make_gaussian_map(int r)
int x, y;
float t, g;
#ifdef __clang_analyzer__
c = malloc(sizeof(conv) + size * size * sizeof(float));
#else
c = (conv *) EMALLOC(char, sizeof(conv) + size * size * sizeof(float));
#endif
c->size = size;
c->data = (float *)(c + 1);
@ -631,6 +635,9 @@ make_shadow(float opacity, int width, int height)
}
}
#ifdef __clang_analyzer__
free(data);
#endif
return ximage;
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2019 Kim Woelders
* Copyright (C) 2004-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -353,6 +353,9 @@ doFocusToEwin(EWin * ewin, int why)
break;
case FOCUS_EWIN_NEW:
if (!ewin)
return;
if (Mode.place.doing_manual)
goto check_focus_new;

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2018 Kim Woelders
* Copyright (C) 2004-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -90,6 +90,8 @@ static const EOpt Eopts[] = {
{'X', 1, NULL, NULL, NULL},
};
#define Strtoi(s, base) ((s) ? strtol(s, NULL, base) : 0)
int
main(int argc, char **argv)
{
@ -189,7 +191,7 @@ main(int argc, char **argv)
break;
case 's':
Mode.wm.single = 1;
Dpy.screen = strtoul(eoptarg, NULL, 10);
Dpy.screen = Strtoi(eoptarg, 10);
break;
case 'S':
SetSMID(eoptarg);
@ -212,13 +214,13 @@ main(int argc, char **argv)
break;
#ifdef USE_EXT_INIT_WIN
case 'X':
ExtInitWinSet(strtoul(eoptarg, NULL, 0));
ExtInitWinSet(Strtoi(eoptarg, 0));
Mode.wm.restart = 1;
break;
#endif
case 'm':
Mode.wm.master = 0;
Mode.wm.master_screen = strtoul(eoptarg, NULL, 10);
Mode.wm.master_screen = Strtoi(eoptarg, 10);
break;
}
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2018 Kim Woelders
* Copyright (C) 2004-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -427,6 +427,23 @@ MenuItemCreate(const char *text, const char *icon,
return mi;
}
static void
MenuItemDestroy(MenuItem * mi, int destroying)
{
int i;
Efree(mi->text);
Efree(mi->icon);
Efree(mi->params);
for (i = 0; i < 3; i++)
PmapMaskFree(&(mi->pmm[i]));
if (!destroying && mi->win)
EDestroyWindow(mi->win);
else
EventCallbackUnregister(mi->win, MenuItemHandleEvents, mi);
Efree(mi);
}
static int
_MenuStyleMatchName(const void *data, const void *match)
{
@ -609,7 +626,7 @@ MenuDestroy(Menu * m)
void
MenuEmpty(Menu * m, int destroying)
{
int i, j;
int i;
MenuItem *mi;
for (i = 0; i < m->num; i++)
@ -621,16 +638,7 @@ MenuEmpty(Menu * m, int destroying)
mi->child->ref_count--;
MenuDestroy(mi->child);
}
Efree(mi->text);
Efree(mi->icon);
Efree(mi->params);
for (j = 0; j < 3; j++)
PmapMaskFree(&(mi->pmm[j]));
if (!destroying && mi->win)
EDestroyWindow(mi->win);
else
EventCallbackUnregister(mi->win, MenuItemHandleEvents, mi);
Efree(mi);
MenuItemDestroy(mi, destroying);
}
EFREE_NULL(m->items);
m->num = 0;
@ -672,7 +680,10 @@ MenuAddItem(Menu * m, MenuItem * item)
items = EREALLOC(MenuItem *, m->items, m->num + 1);
if (!items)
return;
{
MenuItemDestroy(item, 1);
return;
}
items[m->num] = item;
m->items = items;

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2018 Kim Woelders
* Copyright (C) 2004-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -1116,14 +1116,6 @@ PagerHiwinInit(Pager * p, EWin * ewin)
Hiwin *phi = hiwin;
int wx, wy, ww, wh, px, py;
if (!phi)
{
phi = HiwinCreate();
if (!phi)
return;
hiwin = phi;
}
wx = (EwinGetVX(ewin) * p->dw) / WinGetW(VROOT);
wy = (EwinGetVY(ewin) * p->dh) / WinGetH(VROOT);
ww = (EoGetW(ewin) * p->dw) / WinGetW(VROOT);
@ -1151,14 +1143,19 @@ PagerHiwinShow(Pager * p, EWin * ewin, int zoom, int confine)
if (MenusActive()) /* Don't show HiWin when menu is up */
return;
if (!phi || ewin)
Dprintf("%s\n", __func__);
if (!phi)
{
PagerHiwinInit(p, ewin);
phi = hiwin;
phi = HiwinCreate();
if (!phi)
return;
hiwin = phi;
}
if (ewin)
PagerHiwinInit(p, ewin);
HiwinShow(phi, ewin, zoom, confine);
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2019 Kim Woelders
* Copyright (C) 2004-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -554,7 +554,7 @@ doSMExit(int mode, const char *params)
l += Esnprintf(s + l, sizeof(s) - l, " -X %#x", new_init_win_ext);
#endif
if (ss)
l += Esnprintf(s + l, sizeof(s) - l, " -t %s", ss);
Esnprintf(s + l, sizeof(s) - l, " -t %s", ss);
if (EDebug(EDBUG_TYPE_SESSION))
Eprintf("%s: exec %s\n", __func__, s);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2004-2018 Kim Woelders
* Copyright (C) 2004-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -256,6 +256,7 @@ EobjListFind(const EobjList * ewl, EX_Window win)
return NULL;
}
#if 0
static int
EobjListTypeCount(const EobjList * ewl, int type)
{
@ -267,6 +268,7 @@ EobjListTypeCount(const EobjList * ewl, int type)
return n;
}
#endif
/*
* The global object/client lists
@ -348,16 +350,10 @@ EwinListStackGet(int *num)
static EWin **lst = NULL;
static int nalloc = 0;
const EobjList *ewl;
int i, j, newins;
int i, j;
EObj *eo;
ewl = &EwinListStack;
newins = EobjListTypeCount(ewl, EOBJ_TYPE_EWIN);
if (nalloc < newins)
{
nalloc = (newins + 16) & ~0xf; /* 16 at the time */
lst = EREALLOC(EWin *, lst, nalloc);
}
for (i = j = 0; i < ewl->nwins; i++)
{
@ -365,6 +361,12 @@ EwinListStackGet(int *num)
if (eo->type != EOBJ_TYPE_EWIN)
continue;
if (nalloc <= j)
{
nalloc += 16; /* 16 at the time */
lst = EREALLOC(EWin *, lst, nalloc);
}
lst[j++] = (EWin *) eo;
}
@ -384,17 +386,10 @@ EwinListGetForDesk(int *num, Desk * dsk)
static EWin **lst = NULL;
static int nalloc = 0;
const EobjList *ewl;
int i, j, newins;
int i, j;
EObj *eo;
ewl = &EwinListStack;
newins = EobjListTypeCount(ewl, EOBJ_TYPE_EWIN);
/* Too many - who cares. */
if (nalloc < newins)
{
nalloc = (newins + 16) & ~0xf; /* 16 at the time */
lst = EREALLOC(EWin *, lst, nalloc);
}
for (i = j = 0; i < ewl->nwins; i++)
{
@ -402,6 +397,12 @@ EwinListGetForDesk(int *num, Desk * dsk)
if (eo->type != EOBJ_TYPE_EWIN || eo->desk != dsk)
continue;
if (nalloc <= j)
{
nalloc += 16; /* 16 at the time */
lst = EREALLOC(EWin *, lst, nalloc);
}
lst[j++] = (EWin *) eo;
}