malloc + memset -> zalloc
And for clients using the xmalloc helper, use xzalloc. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
committed by
Kristian Høgsberg
parent
b1bc4a68b0
commit
f3d62276d2
+1
-3
@@ -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");
|
||||
|
||||
+1
-3
@@ -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);
|
||||
|
||||
+5
-11
@@ -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);
|
||||
|
||||
+1
-3
@@ -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");
|
||||
|
||||
+1
-2
@@ -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);
|
||||
|
||||
+1
-2
@@ -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);
|
||||
|
||||
+1
-3
@@ -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);
|
||||
|
||||
+2
-4
@@ -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);
|
||||
|
||||
+1
-3
@@ -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);
|
||||
|
||||
+3
-7
@@ -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;
|
||||
|
||||
+1
-2
@@ -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);
|
||||
|
||||
+13
-17
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user