mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
xmalloc: add xmemdup() and use to replace some uses of xmalloc+memcpy
This commit is contained in:
parent
853be450bb
commit
e8b04e0e2c
4 changed files with 14 additions and 18 deletions
15
config.c
15
config.c
|
|
@ -2902,8 +2902,7 @@ add_default_key_bindings(struct config *conf)
|
||||||
};
|
};
|
||||||
|
|
||||||
conf->bindings.key.count = ALEN(bindings);
|
conf->bindings.key.count = ALEN(bindings);
|
||||||
conf->bindings.key.arr = xmalloc(sizeof(bindings));
|
conf->bindings.key.arr = xmemdup(bindings, sizeof(bindings));
|
||||||
memcpy(conf->bindings.key.arr, bindings, sizeof(bindings));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2954,8 +2953,7 @@ add_default_search_bindings(struct config *conf)
|
||||||
};
|
};
|
||||||
|
|
||||||
conf->bindings.search.count = ALEN(bindings);
|
conf->bindings.search.count = ALEN(bindings);
|
||||||
conf->bindings.search.arr = xmalloc(sizeof(bindings));
|
conf->bindings.search.arr = xmemdup(bindings, sizeof(bindings));
|
||||||
memcpy(conf->bindings.search.arr, bindings, sizeof(bindings));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -2970,8 +2968,7 @@ add_default_url_bindings(struct config *conf)
|
||||||
};
|
};
|
||||||
|
|
||||||
conf->bindings.url.count = ALEN(bindings);
|
conf->bindings.url.count = ALEN(bindings);
|
||||||
conf->bindings.url.arr = xmalloc(sizeof(bindings));
|
conf->bindings.url.arr = xmemdup(bindings, sizeof(bindings));
|
||||||
memcpy(conf->bindings.url.arr, bindings, sizeof(bindings));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -2994,8 +2991,7 @@ add_default_mouse_bindings(struct config *conf)
|
||||||
};
|
};
|
||||||
|
|
||||||
conf->bindings.mouse.count = ALEN(bindings);
|
conf->bindings.mouse.count = ALEN(bindings);
|
||||||
conf->bindings.mouse.arr = xmalloc(sizeof(bindings));
|
conf->bindings.mouse.arr = xmemdup(bindings, sizeof(bindings));
|
||||||
memcpy(conf->bindings.mouse.arr, bindings, sizeof(bindings));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void NOINLINE
|
static void NOINLINE
|
||||||
|
|
@ -3388,8 +3384,7 @@ key_binding_list_clone(struct config_key_binding_list *dst,
|
||||||
if (old->aux.master_copy) {
|
if (old->aux.master_copy) {
|
||||||
const size_t len = old->aux.text.len;
|
const size_t len = old->aux.text.len;
|
||||||
new->aux.text.len = len;
|
new->aux.text.len = len;
|
||||||
new->aux.text.data = xmalloc(len);
|
new->aux.text.data = xmemdup(old->aux.text.data, len);
|
||||||
memcpy(new->aux.text.data, old->aux.text.data, len);
|
|
||||||
|
|
||||||
last_master_text_len = len;
|
last_master_text_len = len;
|
||||||
last_master_text_data = new->aux.text.data;
|
last_master_text_data = new->aux.text.data;
|
||||||
|
|
|
||||||
6
grid.c
6
grid.c
|
|
@ -263,8 +263,7 @@ grid_snapshot(const struct grid *grid)
|
||||||
int original_stride = stride_for_format_and_width(original_pix_fmt, original_width);
|
int original_stride = stride_for_format_and_width(original_pix_fmt, original_width);
|
||||||
|
|
||||||
size_t original_size = original_stride * original_height;
|
size_t original_size = original_stride * original_height;
|
||||||
void *new_original_data = xmalloc(original_size);
|
void *new_original_data = xmemdup(it->item.original.data, original_size);
|
||||||
memcpy(new_original_data, it->item.original.data, original_size);
|
|
||||||
|
|
||||||
pixman_image_t *new_original_pix = pixman_image_create_bits_no_clear(
|
pixman_image_t *new_original_pix = pixman_image_create_bits_no_clear(
|
||||||
original_pix_fmt, original_width, original_height,
|
original_pix_fmt, original_width, original_height,
|
||||||
|
|
@ -284,8 +283,7 @@ grid_snapshot(const struct grid *grid)
|
||||||
int scaled_stride = stride_for_format_and_width(scaled_pix_fmt, scaled_width);
|
int scaled_stride = stride_for_format_and_width(scaled_pix_fmt, scaled_width);
|
||||||
|
|
||||||
size_t scaled_size = scaled_stride * scaled_height;
|
size_t scaled_size = scaled_stride * scaled_height;
|
||||||
new_scaled_data = xmalloc(scaled_size);
|
new_scaled_data = xmemdup(it->item.scaled.data, scaled_size);
|
||||||
memcpy(new_scaled_data, it->item.scaled.data, scaled_size);
|
|
||||||
|
|
||||||
new_scaled_pix = pixman_image_create_bits_no_clear(
|
new_scaled_pix = pixman_image_create_bits_no_clear(
|
||||||
scaled_pix_fmt, scaled_width, scaled_height, new_scaled_data,
|
scaled_pix_fmt, scaled_width, scaled_height, new_scaled_data,
|
||||||
|
|
|
||||||
|
|
@ -51,11 +51,8 @@ static void
|
||||||
enqueue_data_for_slave(const void *data, size_t len, size_t offset,
|
enqueue_data_for_slave(const void *data, size_t len, size_t offset,
|
||||||
ptmx_buffer_list_t *buffer_list)
|
ptmx_buffer_list_t *buffer_list)
|
||||||
{
|
{
|
||||||
void *copy = xmalloc(len);
|
|
||||||
memcpy(copy, data, len);
|
|
||||||
|
|
||||||
struct ptmx_buffer queued = {
|
struct ptmx_buffer queued = {
|
||||||
.data = copy,
|
.data = xmemdup(data, len),
|
||||||
.len = len,
|
.len = len,
|
||||||
.idx = offset,
|
.idx = offset,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,12 @@ char *xasprintf(const char *format, ...) PRINTF(1) XMALLOC;
|
||||||
char *xvasprintf(const char *format, va_list va) VPRINTF(1) XMALLOC;
|
char *xvasprintf(const char *format, va_list va) VPRINTF(1) XMALLOC;
|
||||||
char32_t *xc32dup(const char32_t *str) XSTRDUP;
|
char32_t *xc32dup(const char32_t *str) XSTRDUP;
|
||||||
|
|
||||||
|
static inline void *
|
||||||
|
xmemdup(const void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
return memcpy(xmalloc(size), ptr, size);
|
||||||
|
}
|
||||||
|
|
||||||
static inline char *
|
static inline char *
|
||||||
xstrjoin(const char *s1, const char *s2)
|
xstrjoin(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue