Commit f3d62276 authored by Peter Hutterer's avatar Peter Hutterer Committed by Kristian H. Kristensen

malloc + memset -> zalloc

And for clients using the xmalloc helper, use xzalloc.
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent b1bc4a68
......@@ -247,9 +247,7 @@ clickdot_create(struct display *display)
{
struct clickdot *clickdot;
clickdot = xmalloc(sizeof *clickdot);
memset(clickdot, 0, sizeof *clickdot);
clickdot = xzalloc(sizeof *clickdot);
clickdot->window = window_create(display);
clickdot->widget = frame_create(clickdot->window, clickdot);
window_set_title(clickdot->window, "Wayland ClickDot");
......
......@@ -791,9 +791,7 @@ cliptest_create(struct display *display)
{
struct cliptest *cliptest;
cliptest = xmalloc(sizeof *cliptest);
memset(cliptest, 0, sizeof *cliptest);
cliptest = xzalloc(sizeof *cliptest);
cliptest->surface.geometry = &cliptest->geometry;
cliptest->surface.transform.enabled = 0;
geometry_init(&cliptest->geometry);
......
......@@ -409,8 +409,7 @@ panel_add_clock(struct panel *panel)
return;
}
clock = xmalloc(sizeof *clock);
memset(clock, 0, sizeof *clock);
clock = xzalloc(sizeof *clock);
clock->panel = panel;
panel->clock = clock;
clock->clock_fd = timerfd;
......@@ -512,8 +511,7 @@ panel_create(struct desktop *desktop)
struct panel *panel;
struct weston_config_section *s;
panel = xmalloc(sizeof *panel);
memset(panel, 0, sizeof *panel);
panel = xzalloc(sizeof *panel);
panel->base.configure = panel_configure;
panel->window = window_create_custom(desktop->display);
......@@ -582,8 +580,7 @@ panel_add_launcher(struct panel *panel, const char *icon, const char *path)
char *start, *p, *eq, **ps;
int i, j, k;
launcher = xmalloc(sizeof *launcher);
memset(launcher, 0, sizeof *launcher);
launcher = xzalloc(sizeof *launcher);
launcher->icon = load_icon_or_fallback(icon);
launcher->path = strdup(path);
......@@ -841,8 +838,7 @@ unlock_dialog_create(struct desktop *desktop)
struct display *display = desktop->display;
struct unlock_dialog *dialog;
dialog = xmalloc(sizeof *dialog);
memset(dialog, 0, sizeof *dialog);
dialog = xzalloc(sizeof *dialog);
dialog->window = window_create_custom(display);
dialog->widget = frame_create(dialog->window, dialog);
......@@ -987,9 +983,7 @@ background_create(struct desktop *desktop)
struct weston_config_section *s;
char *type;
background = xmalloc(sizeof *background);
memset(background, 0, sizeof *background);
background = xzalloc(sizeof *background);
background->base.configure = background_configure;
background->window = window_create_custom(desktop->display);
background->widget = window_add_widget(background->window, background);
......
......@@ -567,9 +567,7 @@ dnd_create(struct display *display)
int32_t width, height;
unsigned int i;
dnd = xmalloc(sizeof *dnd);
memset(dnd, 0, sizeof *dnd);
dnd = xzalloc(sizeof *dnd);
dnd->window = window_create(display);
dnd->widget = frame_create(dnd->window, dnd);
window_set_title(dnd->window, "Wayland Drag and Drop Demo");
......
......@@ -401,8 +401,7 @@ gears_create(struct display *display)
struct timeval tv;
int i;
gears = malloc(sizeof *gears);
memset(gears, 0, sizeof *gears);
gears = zalloc(sizeof *gears);
gears->d = display;
gears->window = window_create(display);
gears->widget = frame_create(gears->window, gears);
......
......@@ -358,10 +358,9 @@ image_create(struct display *display, const char *filename,
struct image *image;
char *b, *copy, title[512];;
image = malloc(sizeof *image);
image = zalloc(sizeof *image);
if (image == NULL)
return image;
memset(image, 0, sizeof *image);
copy = strdup(filename);
b = basename(copy);
......
......@@ -836,9 +836,7 @@ keyboard_create(struct output *output, struct virtual_keyboard *virtual_keyboard
layout = get_current_layout(virtual_keyboard);
keyboard = xmalloc(sizeof *keyboard);
memset(keyboard, 0, sizeof *keyboard);
keyboard = xzalloc(sizeof *keyboard);
keyboard->keyboard = virtual_keyboard;
keyboard->window = window_create_custom(virtual_keyboard->display);
keyboard->widget = window_add_widget(keyboard->window, keyboard);
......
......@@ -404,13 +404,12 @@ compositor_create_surface(struct wl_client *client,
struct nested *nested = wl_resource_get_user_data(resource);
struct nested_surface *surface;
surface = malloc(sizeof *surface);
surface = zalloc(sizeof *surface);
if (surface == NULL) {
wl_resource_post_no_memory(resource);
return;
}
memset(surface, 0, sizeof *surface);
surface->nested = nested;
display_acquire_window_surface(nested->display,
......@@ -568,10 +567,9 @@ nested_create(struct display *display)
{
struct nested *nested;
nested = malloc(sizeof *nested);
nested = zalloc(sizeof *nested);
if (nested == NULL)
return nested;
memset(nested, 0, sizeof *nested);
nested->window = window_create(display);
nested->widget = frame_create(nested->window, nested);
......
......@@ -233,9 +233,7 @@ resizor_create(struct display *display)
{
struct resizor *resizor;
resizor = xmalloc(sizeof *resizor);
memset(resizor, 0, sizeof *resizor);
resizor = xzalloc(sizeof *resizor);
resizor->window = window_create(display);
resizor->widget = frame_create(resizor->window, resizor);
window_set_title(resizor->window, "Wayland Resizor");
......
......@@ -230,9 +230,7 @@ homescreen_create(struct tablet *tablet)
{
struct homescreen *homescreen;
homescreen = xmalloc(sizeof *homescreen);
memset(homescreen, 0, sizeof *homescreen);
homescreen = zalloc (sizeof *homescreen);
homescreen->window = window_create_custom(tablet->display);
homescreen->widget =
window_add_widget(homescreen->window, homescreen);
......@@ -248,9 +246,7 @@ lockscreen_create(struct tablet *tablet)
{
struct lockscreen *lockscreen;
lockscreen = xmalloc(sizeof *lockscreen);
memset(lockscreen, 0, sizeof *lockscreen);
lockscreen = zalloc (sizeof *lockscreen);
lockscreen->window = window_create_custom(tablet->display);
lockscreen->widget =
window_add_widget(lockscreen->window, lockscreen);
......
......@@ -710,12 +710,10 @@ terminal_resize_cells(struct terminal *terminal, int width, int height)
data_pitch = width * sizeof(union utf8_char);
size = data_pitch * height;
data = malloc(size);
data = zalloc(size);
attr_pitch = width * sizeof(struct attr);
data_attr = malloc(attr_pitch * height);
tab_ruler = malloc(width);
memset(data, 0, size);
memset(tab_ruler, 0, width);
tab_ruler = zalloc(width);
attr_init(data_attr, terminal->curr_attr, width * height);
if (terminal->data && terminal->data_attr) {
if (width > terminal->width)
......@@ -2552,9 +2550,7 @@ terminal_create(struct display *display)
cairo_t *cr;
cairo_text_extents_t text_extents;
terminal = xmalloc(sizeof *terminal);
memset(terminal, 0, sizeof *terminal);
terminal = xzalloc(sizeof *terminal);
terminal->color_scheme = &DEFAULT_COLORS;
terminal_init(terminal);
terminal->margin_top = 0;
......
......@@ -230,10 +230,9 @@ view_create(struct display *display,
GFile *file = NULL;
GError *error = NULL;
view = malloc(sizeof *view);
view = zalloc(sizeof *view);
if (view == NULL)
return view;
memset(view, 0, sizeof *view);
file = g_file_new_for_commandline_arg(filename);
basename = g_file_get_basename(file);
......
......@@ -1608,8 +1608,7 @@ widget_create(struct window *window, struct surface *surface, void *data)
{
struct widget *widget;
widget = xmalloc(sizeof *widget);
memset(widget, 0, sizeof *widget);
widget = xzalloc(sizeof *widget);
widget->window = window;
widget->surface = surface;
widget->user_data = data;
......@@ -2390,9 +2389,7 @@ frame_button_create(struct frame *frame, void *data, enum frame_button_action ty
struct frame_button *frame_button;
const char *icon = data;
frame_button = xmalloc(sizeof *frame_button);
memset(frame_button, 0, sizeof *frame_button);
frame_button = xzalloc (sizeof *frame_button);
frame_button->icon = cairo_image_surface_create_from_png(icon);
frame_button->widget = widget_add_widget(frame->widget, frame_button);
frame_button->frame = frame;
......@@ -2621,9 +2618,7 @@ frame_create(struct window *window, void *data)
{
struct frame *frame;
frame = xmalloc(sizeof *frame);
memset(frame, 0, sizeof *frame);
frame = xzalloc(sizeof *frame);
frame->widget = window_add_widget(window, frame);
frame->child = widget_add_widget(frame->widget, data);
......@@ -4209,8 +4204,7 @@ window_create_internal(struct display *display,
struct window *window;
struct surface *surface;
window = xmalloc(sizeof *window);
memset(window, 0, sizeof *window);
window = xzalloc(sizeof *window);
wl_list_init(&window->subsurface_list);
window->display = display;
window->parent = parent;
......@@ -4562,11 +4556,10 @@ display_add_output(struct display *d, uint32_t id)
{
struct output *output;
output = malloc(sizeof *output);
output = zalloc(sizeof *output);
if (output == NULL)
return;
memset(output, 0, sizeof *output);
output->display = d;
output->scale = 1;
output->output =
......@@ -4692,11 +4685,10 @@ display_add_input(struct display *d, uint32_t id)
{
struct input *input;
input = malloc(sizeof *input);
input = zalloc(sizeof *input);
if (input == NULL)
return;
memset(input, 0, sizeof *input);
input->display = d;
input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, 1);
input->pointer_focus = NULL;
......@@ -4998,12 +4990,10 @@ display_create(int *argc, char *argv[])
wl_log_set_handler_client(log_handler);
d = malloc(sizeof *d);
d = zalloc(sizeof *d);
if (d == NULL)
return NULL;
memset(d, 0, sizeof *d);
d->display = wl_display_connect(NULL);
if (d->display == NULL) {
fprintf(stderr, "failed to connect to Wayland display: %m\n");
......@@ -5353,6 +5343,12 @@ xmalloc(size_t s)
return fail_on_null(malloc(s));
}
void *
xzalloc(size_t s)
{
return fail_on_null(zalloc(s));
}
char *
xstrdup(const char *s)
{
......
......@@ -27,6 +27,7 @@
#include <wayland-client.h>
#include <cairo.h>
#include "../shared/config-parser.h"
#include "../shared/zalloc.h"
#include "subsurface-client-protocol.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
......@@ -57,6 +58,8 @@ void *
fail_on_null(void *p);
void *
xmalloc(size_t s);
void *
xzalloc(size_t s);
char *
xstrdup(const char *s);
......
......@@ -283,10 +283,9 @@ clipboard_create(struct weston_seat *seat)
{
struct clipboard *clipboard;
clipboard = malloc(sizeof *clipboard);
clipboard = zalloc(sizeof *clipboard);
if (clipboard == NULL)
return NULL;
memset(clipboard, 0, sizeof *clipboard);
clipboard->seat = seat;
clipboard->selection_listener.notify = clipboard_set_selection;
......
......@@ -494,10 +494,9 @@ module_init(struct weston_compositor *ec,
weston_log("colord: initialized\n");
/* create local state object */
cms = malloc(sizeof *cms);
cms = zalloc(sizeof *cms);
if (cms == NULL)
return -1;
memset(cms, 0, sizeof *cms);
cms->ec = ec;
#if !GLIB_CHECK_VERSION(2,36,0)
g_type_init();
......
......@@ -94,10 +94,9 @@ module_init(struct weston_compositor *ec,
weston_log("cms-static: initialized\n");
/* create local state object */
cms = malloc(sizeof *cms);
cms = zalloc(sizeof *cms);
if (cms == NULL)
return -1;
memset(cms, 0, sizeof *cms);
cms->ec = ec;
cms->destroy_listener.notify = cms_notifier_destroy;
......
......@@ -234,7 +234,7 @@ drm_fb_create_dumb(struct drm_compositor *ec, unsigned width, unsigned height)
struct drm_mode_destroy_dumb destroy_arg;
struct drm_mode_map_dumb map_arg;
fb = calloc(1, sizeof *fb);
fb = zalloc(sizeof *fb);
if (!fb)
return NULL;
......@@ -1771,11 +1771,10 @@ create_output_for_connector(struct drm_compositor *ec,
return -1;
}
output = malloc(sizeof *output);
output = zalloc(sizeof *output);
if (output == NULL)
return -1;
memset(output, 0, sizeof *output);
output->base.subpixel = drm_subpixel_to_wayland(connector->subpixel);
output->base.make = "unknown";
output->base.model = "unknown";
......@@ -2000,7 +1999,7 @@ create_sprites(struct drm_compositor *ec)
if (!plane)
continue;
sprite = malloc(sizeof(*sprite) + ((sizeof(uint32_t)) *
sprite = zalloc(sizeof(*sprite) + ((sizeof(uint32_t)) *
plane->count_formats));
if (!sprite) {
weston_log("%s: out of memory\n",
......@@ -2009,8 +2008,6 @@ create_sprites(struct drm_compositor *ec)
continue;
}
memset(sprite, 0, sizeof *sprite);
sprite->possible_crtcs = plane->possible_crtcs;
sprite->plane_id = plane->plane_id;
sprite->current = NULL;
......@@ -2451,10 +2448,9 @@ drm_compositor_create(struct wl_display *display,
weston_log("initializing drm backend\n");
ec = malloc(sizeof *ec);
ec = zalloc(sizeof *ec);
if (ec == NULL)
return NULL;
memset(ec, 0, sizeof *ec);
/* KMS support for sprites is not complete yet, so disable the
* functionality for now. */
......
......@@ -95,10 +95,9 @@ headless_compositor_create_output(struct headless_compositor *c,
struct headless_output *output;
struct wl_event_loop *loop;
output = malloc(sizeof *output);
output = zalloc(sizeof *output);
if (output == NULL)
return -1;
memset(output, 0, sizeof *output);
output->mode.flags =
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
......@@ -161,12 +160,10 @@ headless_compositor_create(struct wl_display *display,
{
struct headless_compositor *c;
c = calloc(1, sizeof *c);
c = zalloc(sizeof *c);
if (c == NULL)
return NULL;
memset(c, 0, sizeof *c);
if (weston_compositor_init(&c->base, display, argc, argv, config) < 0)
goto err_free;
......
......@@ -445,10 +445,9 @@ rdp_compositor_create_output(struct rdp_compositor *c, int width, int height,
struct wl_event_loop *loop;
struct weston_mode *currentMode, *next;
output = malloc(sizeof *output);
output = zalloc(sizeof *output);
if (output == NULL)
return -1;
memset(output, 0, sizeof *output);
wl_list_init(&output->peers);
wl_list_init(&output->base.mode_list);
......@@ -991,12 +990,10 @@ rdp_compositor_create(struct wl_display *display,
char *fd_str;
int fd;
c = malloc(sizeof *c);
c = zalloc(sizeof *c);
if (c == NULL)
return NULL;
memset(c, 0, sizeof *c);
if (weston_compositor_init(&c->base, display, argc, argv, wconfig) < 0)
goto err_free;
......
......@@ -598,11 +598,10 @@ evdev_input_create(struct weston_compositor *c, struct udev *udev,
{
struct rpi_seat *seat;
seat = malloc(sizeof *seat);
seat = zalloc(sizeof *seat);
if (seat == NULL)
return;
memset(seat, 0, sizeof *seat);
weston_seat_init(&seat->base, c, "default");
seat->base.led_update = rpi_led_update;
......
......@@ -249,10 +249,9 @@ wayland_compositor_create_output(struct wayland_compositor *c,
{
struct wayland_output *output;
output = malloc(sizeof *output);
output = zalloc(sizeof *output);
if (output == NULL)
return -1;
memset(output, 0, sizeof *output);
output->mode.flags =
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
......@@ -629,12 +628,10 @@ display_add_seat(struct wayland_compositor *c, uint32_t id)
{
struct wayland_input *input;
input = malloc(sizeof *input);
input = zalloc(sizeof *input);
if (input == NULL)
return;
memset(input, 0, sizeof *input);
weston_seat_init(&input->base, &c->base, "default");
input->compositor = c;
input->seat = wl_registry_bind(c->parent.registry, id,
......@@ -725,12 +722,10 @@ wayland_compositor_create(struct wl_display *display,
struct wl_event_loop *loop;
int fd;
c = malloc(sizeof *c);
c = zalloc(sizeof *c);
if (c == NULL)
return NULL;
memset(c, 0, sizeof *c);
if (weston_compositor_init(&c->base, display, argc, argv,
config) < 0)
goto err_free;
......
......@@ -813,12 +813,10 @@ x11_compositor_create_output(struct x11_compositor *c, int x, int y,
XCB_EVENT_MASK_KEYMAP_STATE |
XCB_EVENT_MASK_FOCUS_CHANGE;
output = malloc(sizeof *output);
output = zalloc(sizeof *output);
if (output == NULL)
return NULL;
memset(output, 0, sizeof *output);
output->mode.flags =
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
......@@ -1464,12 +1462,10 @@ x11_compositor_create(struct wl_display *display,
weston_log("initializing x11 backend\n");
c = malloc(sizeof *c);
c = zalloc(sizeof *c);
if (c == NULL)
return NULL;
memset(c, 0, sizeof *c);
if (weston_compositor_init(&c->base, display, argc, argv, config) < 0)
goto err_free;
......
......@@ -1077,9 +1077,7 @@ weston_buffer_from_resource(struct wl_resource *resource)
buffer = container_of(listener, struct weston_buffer,
destroy_listener);
} else {
buffer = malloc(sizeof *buffer);
memset(buffer, 0, sizeof *buffer);
buffer = zalloc(sizeof *buffer);
buffer->resource = resource;
wl_signal_init(&buffer->destroy_signal);
buffer->destroy_listener.notify = weston_buffer_destroy_handler;
......
......@@ -382,13 +382,12 @@ data_device_start_drag(struct wl_client *client, struct wl_resource *resource,
return;
}
drag = malloc(sizeof *drag);
drag = zalloc(sizeof *drag);
if (drag == NULL) {
wl_resource_post_no_memory(resource);
return;
}
memset(drag, 0, sizeof *drag);
drag->grab.interface = &drag_grab_interface;
drag->client = client;
......
......@@ -552,10 +552,9 @@ evdev_device_create(struct weston_seat *seat, const char *path, int device_fd)
struct weston_compositor *ec;
char devname[256] = "unknown";
device = malloc(sizeof *device);
device = zalloc(sizeof *device);
if (device == NULL)
return NULL;
memset(device, 0, sizeof *device);
ec = seat->compositor;
device->output =
......
......@@ -307,11 +307,10 @@ weston_pointer_create(void)
{
struct weston_pointer *pointer;
pointer = malloc(sizeof *pointer);
pointer = zalloc(sizeof *pointer);
if (pointer == NULL)
return NULL;
memset(pointer, 0, sizeof *pointer);
wl_list_init(&pointer->resource_list);
pointer->focus_listener.notify = lose_pointer_focus;
pointer->default_grab.interface = &default_pointer_grab_interface;
......@@ -345,11 +344,10 @@ weston_keyboard_create(void)
{
struct weston_keyboard *keyboard;
keyboard = malloc(sizeof *keyboard);
keyboard = zalloc(sizeof *keyboard);
if (keyboard == NULL)
return NULL;
memset(keyboard, 0, sizeof *keyboard);
wl_list_init(&keyboard->resource_list);
wl_array_init(&keyboard->keys);
keyboard->focus_listener.notify = lose_keyboard_focus;
......@@ -376,11 +374,10 @@ weston_touch_create(void)
{
struct weston_touch *touch;
touch = malloc(sizeof *touch);
touch = zalloc(sizeof *touch);
if (touch == NULL)
return NULL;
memset(touch, 0, sizeof *touch);
wl_list_init(&touch->resource_list);
touch->focus_listener.notify = lose_touch_focus;
touch->default_grab.interface = &default_touch_grab_interface;
......
......@@ -465,12 +465,11 @@ weston_recorder_create(struct weston_output *output, const char *filename)
stride = output->current->width;
size = stride * 4 * output->current->height;
recorder->frame = malloc(size);
recorder->frame = zalloc(size);
recorder->rect = malloc(size);
recorder->total = 0;
recorder->count = 0;
recorder->output = output;
memset(recorder->frame, 0, size);
if (do_yflip)
recorder->tmpbuf = NULL;
......
......@@ -4443,11 +4443,10 @@ module_init(struct weston_compositor *ec,
unsigned int i;
struct wl_event_loop *loop;
shell = malloc(sizeof *shell);
shell = zalloc(sizeof *shell);
if (shell == NULL)
return -1;
memset(shell, 0, sizeof *shell);
shell->compositor = ec;
shell->destroy_listener.notify = shell_destroy;
......
......@@ -527,11 +527,10 @@ module_init(struct weston_compositor *compositor,
struct tablet_shell *shell;
struct wl_event_loop *loop;
shell = malloc(sizeof *shell);
shell = zalloc(sizeof *shell);
if (shell == NULL)
return -1;
memset(shell, 0, sizeof *shell);
shell->compositor = compositor;
shell->destroy_listener.notify = tablet_shell_destroy;
......
......@@ -132,11 +132,10 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
char filename[16];
struct vt_stat vts;
tty = malloc(sizeof *tty);
tty = zalloc(sizeof *tty);
if (tty == NULL)
return NULL;
memset(tty, 0, sizeof *tty);
tty->compositor = compositor;
tty->vt_func = vt_func;
......
......@@ -338,11 +338,10 @@ udev_seat_create(struct weston_compositor *c, const char *seat_name)
{
struct udev_seat *seat;
seat = malloc(sizeof *seat);
seat = zalloc(sizeof *seat);
if (!seat)
return NULL;
memset(seat, 0, sizeof *seat);
weston_seat_init(&seat->base, c, seat_name);
seat->base.led_update = drm_led_update;
......
......@@ -325,9 +325,7 @@ module_init(struct weston_compositor *compositor,
struct weston_xserver *wxs;
char lockfile[256], display_name[8];
wxs = malloc(sizeof *wxs);
memset(wxs, 0, sizeof *wxs);
wxs = zalloc(sizeof *wxs);
wxs->process.cleanup = weston_xserver_cleanup;
wxs->wl_display = display;
wxs->compositor = compositor;
......
......@@ -990,7 +990,7 @@ weston_wm_window_create(struct weston_wm *wm,
xcb_get_geometry_cookie_t geometry_cookie;
xcb_get_geometry_reply_t *geometry_reply;
window = malloc(sizeof *window);
window = zalloc(sizeof *window);
if (window == NULL) {
wm_log("failed to allocate window\n");
return;
......@@ -1001,7 +1001,6 @@ weston_wm_window_create(struct weston_wm *wm,
values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE;
xcb_change_window_attributes(wm->conn, id, XCB_CW_EVENT_MASK, values);
memset(window, 0, sizeof *window);
window->wm = wm;