Fix possibles segfaults, dead assignment and other division by zero.

Thanks to clang build report
This commit is contained in:
Philippe Pepiot 2010-11-19 19:55:57 +01:00
parent d75746bcf4
commit daeffb324e
8 changed files with 23 additions and 20 deletions

View File

@ -370,7 +370,6 @@ void
enternotify(XCrossingEvent *ev) enternotify(XCrossingEvent *ev)
{ {
Client *c; Client *c;
Systray *s;
int n; int n;
if((ev->mode != NotifyNormal if((ev->mode != NotifyNormal
@ -379,7 +378,7 @@ enternotify(XCrossingEvent *ev)
return; return;
/* Don't handle EnterNotify event if it's about systray */ /* Don't handle EnterNotify event if it's about systray */
if((s = systray_find(ev->window)) || ev->window == traywin) if(systray_find(ev->window) || ev->window == traywin)
return; return;
if(conf.focus_fmouse) if(conf.focus_fmouse)
@ -525,7 +524,6 @@ void
maprequest(XMapRequestEvent *ev) maprequest(XMapRequestEvent *ev)
{ {
XWindowAttributes at; XWindowAttributes at;
Client *c;
Systray *s; Systray *s;
CHECK(XGetWindowAttributes(dpy, ev->window, &at)); CHECK(XGetWindowAttributes(dpy, ev->window, &at));
@ -536,7 +534,7 @@ maprequest(XMapRequestEvent *ev)
ewmh_send_message(s->win, s->win, "_XEMBED", CurrentTime, XEMBED_WINDOW_ACTIVATE, 0, 0, 0); ewmh_send_message(s->win, s->win, "_XEMBED", CurrentTime, XEMBED_WINDOW_ACTIVATE, 0, 0, 0);
systray_update(); systray_update();
} }
else if(!(c = client_gb_win(ev->window))) else if(!client_gb_win(ev->window))
client_manage(ev->window, &at, True); client_manage(ev->window, &at, True);
return; return;

View File

@ -220,7 +220,7 @@ infobar_draw_selbar(int sc)
void void
infobar_draw_taglist(int sc) infobar_draw_taglist(int sc)
{ {
int i, x, j; int i, x;
Client *c = NULL; Client *c = NULL;
Bool is_occupied[MAXTAG + 1]; Bool is_occupied[MAXTAG + 1];
@ -234,7 +234,7 @@ infobar_draw_taglist(int sc)
if(c->screen == sc) if(c->screen == sc)
is_occupied[c->tag] = True; is_occupied[c->tag] = True;
for(i = 1, x = j = 0; i < conf.ntag[sc] + 1; ++i) for(i = 1, x = 0; i < conf.ntag[sc] + 1; ++i)
{ {
/* Autohide tag feature */ /* Autohide tag feature */
if(conf.tagautohide) if(conf.tagautohide)

View File

@ -179,7 +179,7 @@ launcher_execute(Launcher *launcher)
lastwastab = True; lastwastab = True;
/* start a new round of tabbing */ /* start a new round of tabbing */
if (!found) if (found == False)
tabhits = 0; tabhits = 0;
pos = strlen(buf); pos = strlen(buf);
@ -280,19 +280,20 @@ complete_on_command(char *start, size_t hits)
} }
dirname = strtok(NULL, ":"); dirname = strtok(NULL, ":");
} }
qsort(namelist, n, sizeof(char *), qsort_string_compare);
free(path); free(path);
if(n > 0) if(n > 0)
{ {
qsort(namelist, n, sizeof(char *), qsort_string_compare);
ret = xstrdup(namelist[((hits > 0) ? hits - 1 : 0) % n] + strlen(start)); ret = xstrdup(namelist[((hits > 0) ? hits - 1 : 0) % n] + strlen(start));
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
free(namelist[i]); free(namelist[i]);
}
free(namelist); free(namelist);
}
return ret; return ret;
} }

View File

@ -325,7 +325,10 @@ multi_tile(int screen, Position type)
{ {
if(type == Top) if(type == Top)
mastergeo.y = (n <= nmaster) ? (uint)sg.y : sg.y + (sg.height - mwfact) - BORDH; mastergeo.y = (n <= nmaster) ? (uint)sg.y : sg.y + (sg.height - mwfact) - BORDH;
if (nmaster != 0)
mastergeo.width = (sg.width / nmaster) - (BORDH * 4); mastergeo.width = (sg.width / nmaster) - (BORDH * 4);
else
mastergeo.width = sg.width - (BORDH * 4);
mastergeo.height = (n <= nmaster) ? (uint)(sg.height - BORDH) : mwfact; mastergeo.height = (n <= nmaster) ? (uint)(sg.height - BORDH) : mwfact;
} }
else else
@ -333,7 +336,10 @@ multi_tile(int screen, Position type)
if(type == Left) if(type == Left)
mastergeo.x = (n <= nmaster) ? (uint)sg.x : (sg.x + sg.width) - mwfact - (BORDH * 2); mastergeo.x = (n <= nmaster) ? (uint)sg.x : (sg.x + sg.width) - mwfact - (BORDH * 2);
mastergeo.width = (n <= nmaster) ? (uint)(sg.width - (BORDH * 2)) : mwfact; mastergeo.width = (n <= nmaster) ? (uint)(sg.width - (BORDH * 2)) : mwfact;
mastergeo.height = (sg.height / nmaster) - BORDH; if (nmaster != 0)
mastergeo.height = sg.height - BORDH;
else
mastergeo.height = BORDH;
} }
/* TILED SIZE */ /* TILED SIZE */

View File

@ -100,7 +100,7 @@ push_keyword(struct keyword *tail, enum keyword_t type, char *buf, size_t *offse
if (*offset != 0) { if (*offset != 0) {
buf[*offset] = '\0'; buf[*offset] = '\0';
if (!strcmp(buf, INCLUDE_CMD)) if (!strcmp(buf, INCLUDE_CMD))
type = kw->type = INCLUDE; kw->type = INCLUDE;
else else
kw->name = strdup(buf); kw->name = strdup(buf);
*offset = 0; *offset = 0;

View File

@ -195,7 +195,7 @@ void
statustext_handle(int sc, char *str) statustext_handle(int sc, char *str)
{ {
char *lastst; char *lastst;
int i, nr, ng, ns, len, sw = 0; int i, nr, ng, ns, sw = 0;
StatusRec r[128]; StatusRec r[128];
StatusGraph g[128]; StatusGraph g[128];
StatusText s[128]; StatusText s[128];
@ -213,7 +213,6 @@ statustext_handle(int sc, char *str)
lastst = infobar[sc].statustext; lastst = infobar[sc].statustext;
infobar[sc].statustext = xstrdup(str); infobar[sc].statustext = xstrdup(str);
len = ((strlen(str) > MAXSTATUS) ? MAXSTATUS : strlen(str));
/* Store rectangles, located text & images properties. */ /* Store rectangles, located text & images properties. */
nr = statustext_rectangle(r, str); nr = statustext_rectangle(r, str);

View File

@ -625,10 +625,10 @@ void
uicb_tag_rename(uicb_t cmd) uicb_tag_rename(uicb_t cmd)
{ {
screen_get_sel(); screen_get_sel();
size_t len;
char *str; char *str;
size_t len;
if(!cmd || !(len = strlen(cmd))) if(!cmd || !strlen(cmd))
return; return;
str = tags[selscreen][seltag[selscreen]].name; str = tags[selscreen][seltag[selscreen]].name;

View File

@ -36,7 +36,6 @@ int
errorhandler(Display *d, XErrorEvent *event) errorhandler(Display *d, XErrorEvent *event)
{ {
char mess[256]; char mess[256];
Client *c;
/* Check if there is another WM running */ /* Check if there is another WM running */
if(BadAccess == event->error_code if(BadAccess == event->error_code
@ -48,7 +47,7 @@ errorhandler(Display *d, XErrorEvent *event)
* 42 = X_SetInputFocus * 42 = X_SetInputFocus
* 28 = X_GrabButton * 28 = X_GrabButton
*/ */
if((c = client_gb_win(event->resourceid))) if(client_gb_win(event->resourceid))
if(event->error_code == BadWindow if(event->error_code == BadWindow
|| event->request_code == 42 || event->request_code == 42
|| event->request_code == 28) || event->request_code == 28)