Fix overlapping detection. Fix an use after free. Fixes #41

This commit is contained in:
LemonBoy 2014-02-20 20:21:41 +00:00
parent b60e45ee08
commit 64a81bea0e

15
bar.c
View File

@ -147,8 +147,6 @@ parse_color (const char *str, char **end, const uint32_t def)
ret = (nc_reply) ? nc_reply->pixel : def; ret = (nc_reply) ? nc_reply->pixel : def;
free(nc_reply); free(nc_reply);
printf("k?\n");
if (end) if (end)
*end = (char *)str + str_len; *end = (char *)str + str_len;
@ -455,11 +453,12 @@ get_randr_monitors (void)
num = xcb_randr_get_screen_resources_current_outputs_length(rres_reply); num = xcb_randr_get_screen_resources_current_outputs_length(rres_reply);
outputs = xcb_randr_get_screen_resources_current_outputs(rres_reply); outputs = xcb_randr_get_screen_resources_current_outputs(rres_reply);
free(rres_reply);
/* There should be at least one output */ /* There should be at least one output */
if (num < 1) if (num < 1) {
free(rres_reply);
return; return;
}
xcb_rectangle_t rects[num]; xcb_rectangle_t rects[num];
@ -483,6 +482,7 @@ get_randr_monitors (void)
if (!ci_reply) { if (!ci_reply) {
fprintf(stderr, "Failed to get RandR ctrc info\n"); fprintf(stderr, "Failed to get RandR ctrc info\n");
free(rres_reply);
return; return;
} }
@ -496,6 +496,8 @@ get_randr_monitors (void)
valid++; valid++;
} }
free(rres_reply);
/* Check for clones and inactive outputs */ /* Check for clones and inactive outputs */
for (int i = 0; i < num; i++) { for (int i = 0; i < num; i++) {
if (rects[i].width == 0) if (rects[i].width == 0)
@ -503,9 +505,10 @@ get_randr_monitors (void)
for (int j = 0; j < num; j++) { for (int j = 0; j < num; j++) {
/* Does I countain J ? */ /* Does I countain J ? */
if (i != j && rects[j].width) { if (i != j && rects[j].width) {
if (rects[j].x >= rects[i].x && rects[j].x <= rects[i].x + rects[j].width && if (rects[j].x >= rects[i].x && rects[j].x + rects[j].width <= rects[i].x + rects[i].width &&
rects[j].y >= rects[i].y && rects[j].y <= rects[i].y + rects[i].height) { rects[j].y >= rects[i].y && rects[j].y + rects[j].height <= rects[i].y + rects[i].height) {
rects[j].width = 0; rects[j].width = 0;
valid--; valid--;
} }