Merge pull request #1101 from martinetd/static-analysis

Static analysis fixes
This commit is contained in:
emersion 2018-06-30 12:57:48 +01:00 committed by GitHub
commit 167105e606
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 50 additions and 28 deletions

View File

@ -203,6 +203,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
wlr_log(L_ERROR, "failed to start backend '%s'", name);
wlr_backend_destroy(backend);
wlr_session_destroy(session);
free(names);
return NULL;
}
@ -210,12 +211,14 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display,
wlr_log(L_ERROR, "failed to add backend '%s'", name);
wlr_backend_destroy(backend);
wlr_session_destroy(session);
free(names);
return NULL;
}
name = strtok_r(NULL, ",", &saveptr);
}
free(names);
return backend;
}

View File

@ -83,8 +83,8 @@ static void set_plane_props(struct atomic *atom, struct wlr_drm_plane *plane,
// The src_* properties are in 16.16 fixed point
atomic_add(atom, id, props->src_x, 0);
atomic_add(atom, id, props->src_y, 0);
atomic_add(atom, id, props->src_w, plane->surf.width << 16);
atomic_add(atom, id, props->src_h, plane->surf.height << 16);
atomic_add(atom, id, props->src_w, (uint64_t)plane->surf.width << 16);
atomic_add(atom, id, props->src_h, (uint64_t)plane->surf.height << 16);
atomic_add(atom, id, props->crtc_w, plane->surf.width);
atomic_add(atom, id, props->crtc_h, plane->surf.height);
atomic_add(atom, id, props->fb_id, fb_id);

View File

@ -973,7 +973,7 @@ int handle_drm_event(int fd, uint32_t mask, void *data) {
}
void restore_drm_outputs(struct wlr_drm_backend *drm) {
uint64_t to_close = (1 << wl_list_length(&drm->outputs)) - 1;
uint64_t to_close = (1L << wl_list_length(&drm->outputs)) - 1;
struct wlr_drm_connector *conn;
wl_list_for_each(conn, &drm->outputs, link) {

View File

@ -39,7 +39,7 @@ struct wlr_input_device *wlr_headless_add_input_device(
wlr_device->keyboard = calloc(1, sizeof(struct wlr_keyboard));
if (wlr_device->keyboard == NULL) {
wlr_log(L_ERROR, "Unable to allocate wlr_keyboard");
return NULL;
goto error;
}
wlr_keyboard_init(wlr_device->keyboard, NULL);
break;
@ -47,7 +47,7 @@ struct wlr_input_device *wlr_headless_add_input_device(
wlr_device->pointer = calloc(1, sizeof(struct wlr_pointer));
if (wlr_device->pointer == NULL) {
wlr_log(L_ERROR, "Unable to allocate wlr_pointer");
return NULL;
goto error;
}
wlr_pointer_init(wlr_device->pointer, NULL);
break;
@ -55,7 +55,7 @@ struct wlr_input_device *wlr_headless_add_input_device(
wlr_device->touch = calloc(1, sizeof(struct wlr_touch));
if (wlr_device->touch == NULL) {
wlr_log(L_ERROR, "Unable to allocate wlr_touch");
return NULL;
goto error;
}
wlr_touch_init(wlr_device->touch, NULL);
break;
@ -63,7 +63,7 @@ struct wlr_input_device *wlr_headless_add_input_device(
wlr_device->tablet_tool = calloc(1, sizeof(struct wlr_tablet_tool));
if (wlr_device->tablet_tool == NULL) {
wlr_log(L_ERROR, "Unable to allocate wlr_tablet_tool");
return NULL;
goto error;
}
wlr_tablet_tool_init(wlr_device->tablet_tool, NULL);
break;
@ -71,7 +71,7 @@ struct wlr_input_device *wlr_headless_add_input_device(
wlr_device->tablet_pad = calloc(1, sizeof(struct wlr_tablet_pad));
if (wlr_device->tablet_pad == NULL) {
wlr_log(L_ERROR, "Unable to allocate wlr_tablet_pad");
return NULL;
goto error;
}
wlr_tablet_pad_init(wlr_device->tablet_pad, NULL);
break;
@ -84,4 +84,7 @@ struct wlr_input_device *wlr_headless_add_input_device(
}
return wlr_device;
error:
free(device);
return NULL;
}

View File

@ -159,7 +159,9 @@ static void communicate(int sock) {
}
error:
send_msg(sock, ret ? -1 : fd, &ret, sizeof(ret));
if (fd >= 0) {
close(fd);
}
break;

View File

@ -220,7 +220,7 @@ static void xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *x
struct wlr_wl_output *output = data;
assert(output && output->xdg_toplevel == xdg_toplevel);
if (width == 0 && height == 0) {
if (width == 0 || height == 0) {
return;
}
// loop over states for maximized etc?

View File

@ -38,10 +38,8 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
}
struct wlr_wl_output *output = wl_surface_get_user_data(surface);
assert(output);
struct wlr_wl_pointer *pointer = output_get_pointer(output);
if (output == NULL) {
return;
}
output->enter_serial = serial;
backend->current_pointer = pointer;
@ -56,6 +54,7 @@ static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer,
}
struct wlr_wl_output *output = wl_surface_get_user_data(surface);
assert(output);
output->enter_serial = 0;
if (backend->current_pointer == NULL ||

View File

@ -245,13 +245,13 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
x11->xlib_conn = XOpenDisplay(x11_display);
if (!x11->xlib_conn) {
wlr_log(L_ERROR, "Failed to open X connection");
return NULL;
goto error_x11;
}
x11->xcb_conn = XGetXCBConnection(x11->xlib_conn);
if (!x11->xcb_conn || xcb_connection_has_error(x11->xcb_conn)) {
wlr_log(L_ERROR, "Failed to open xcb connection");
goto error_x11;
goto error_display;
}
XSetEventQueueOwner(x11->xlib_conn, XCBOwnsEventQueue);
@ -262,7 +262,7 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
x11->event_source = wl_event_loop_add_fd(ev, fd, events, x11_event, x11);
if (!x11->event_source) {
wlr_log(L_ERROR, "Could not create event source");
goto error_x11;
goto error_display;
}
x11->screen = xcb_setup_roots_iterator(xcb_get_setup(x11->xcb_conn)).data;
@ -291,8 +291,9 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
error_event:
wl_event_source_remove(x11->event_source);
error_x11:
error_display:
XCloseDisplay(x11->xlib_conn);
error_x11:
free(x11);
return NULL;
}

View File

@ -25,9 +25,12 @@ void wlr_renderer_init(struct wlr_renderer *renderer,
}
void wlr_renderer_destroy(struct wlr_renderer *r) {
if (!r) {
return;
}
wlr_signal_emit_safe(&r->events.destroy, r);
if (r && r->impl && r->impl->destroy) {
if (r->impl && r->impl->destroy) {
r->impl->destroy(r);
} else {
free(r);

View File

@ -381,12 +381,6 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
layer_surface->client_pending.margin.bottom,
layer_surface->client_pending.margin.left);
struct roots_layer_surface *roots_surface =
calloc(1, sizeof(struct roots_layer_surface));
if (!roots_surface) {
return;
}
if (!layer_surface->output) {
struct roots_input *input = desktop->server->input;
struct roots_seat *seat = input_last_active_seat(input);
@ -409,6 +403,12 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
}
}
struct roots_layer_surface *roots_surface =
calloc(1, sizeof(struct roots_layer_surface));
if (!roots_surface) {
return;
}
roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&layer_surface->surface->events.commit,
&roots_surface->surface_commit);

View File

@ -84,6 +84,7 @@ static void manager_handle_capture_output(struct wl_client *client,
&zwlr_export_dmabuf_frame_v1_interface, version, id);
if (frame->resource == NULL) {
wl_client_post_no_memory(client);
free(frame);
return;
}
wl_resource_set_implementation(frame->resource, &frame_impl, frame,

View File

@ -144,6 +144,7 @@ void wlr_keyboard_init(struct wlr_keyboard *kb,
wl_signal_init(&kb->events.modifiers);
wl_signal_init(&kb->events.keymap);
wl_signal_init(&kb->events.repeat_info);
kb->keymap_fd = -1;
// Sane defaults
kb->repeat_info.rate = 25;
@ -156,7 +157,9 @@ void wlr_keyboard_destroy(struct wlr_keyboard *kb) {
}
xkb_state_unref(kb->xkb_state);
xkb_keymap_unref(kb->keymap);
if (kb->keymap_fd >= 0) {
close(kb->keymap_fd);
}
if (kb->impl && kb->impl->destroy) {
kb->impl->destroy(kb);
} else {
@ -212,7 +215,7 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
keymap_str = xkb_keymap_get_as_string(kb->keymap,
XKB_KEYMAP_FORMAT_TEXT_V1);
kb->keymap_size = strlen(keymap_str) + 1;
if (kb->keymap_fd) {
if (kb->keymap_fd >= 0) {
close(kb->keymap_fd);
}
kb->keymap_fd = os_create_anonymous_file(kb->keymap_size);
@ -228,6 +231,7 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
}
strcpy(ptr, keymap_str);
free(keymap_str);
munmap(ptr, kb->keymap_size);
for (size_t i = 0; i < kb->num_keycodes; ++i) {
xkb_keycode_t keycode = kb->keycodes[i] + 8;
@ -244,7 +248,10 @@ err:
kb->xkb_state = NULL;
xkb_keymap_unref(keymap);
kb->keymap = NULL;
if (kb->keymap_fd >= 0) {
close(kb->keymap_fd);
kb->keymap_fd = -1;
}
free(keymap_str);
}

View File

@ -486,8 +486,8 @@ bool wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when,
pixman_region32_intersect(&render_damage, &render_damage, damage);
}
if (when == NULL) {
struct timespec now;
if (when == NULL) {
clock_gettime(CLOCK_MONOTONIC, &now);
when = &now;
}

View File

@ -29,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "util/os-compatibility.h"
@ -61,6 +62,7 @@ int create_tmpfile_cloexec(char *tmpname)
{
int fd;
mode_t prev_umask = umask(0066);
#ifdef HAVE_MKOSTEMP
fd = mkostemp(tmpname, O_CLOEXEC);
if (fd >= 0)
@ -72,6 +74,7 @@ int create_tmpfile_cloexec(char *tmpname)
unlink(tmpname);
}
#endif
umask(prev_umask);
return fd;
}