mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
Introduce a xreallocarray and convert a few xcalloc instances that do
not require zero'ing.
This commit is contained in:
parent
0bbe0ad98c
commit
a4a414b68b
1
calmwm.h
1
calmwm.h
@ -559,6 +559,7 @@ void u_spawn(char *);
|
|||||||
|
|
||||||
void *xcalloc(size_t, size_t);
|
void *xcalloc(size_t, size_t);
|
||||||
void *xmalloc(size_t);
|
void *xmalloc(size_t);
|
||||||
|
void *xreallocarray(void *, size_t, size_t);
|
||||||
char *xstrdup(const char *);
|
char *xstrdup(const char *);
|
||||||
int xasprintf(char **, const char *, ...)
|
int xasprintf(char **, const char *, ...)
|
||||||
__attribute__((__format__ (printf, 2, 3)))
|
__attribute__((__format__ (printf, 2, 3)))
|
||||||
|
2
group.c
2
group.c
@ -91,7 +91,7 @@ group_restack(struct group_ctx *gc)
|
|||||||
if (cc->stackingorder > highstack)
|
if (cc->stackingorder > highstack)
|
||||||
highstack = cc->stackingorder;
|
highstack = cc->stackingorder;
|
||||||
}
|
}
|
||||||
winlist = xcalloc((highstack + 1), sizeof(*winlist));
|
winlist = xreallocarray(NULL, (highstack + 1), sizeof(*winlist));
|
||||||
|
|
||||||
/* Invert the stacking order for XRestackWindows(). */
|
/* Invert the stacking order for XRestackWindows(). */
|
||||||
TAILQ_FOREACH(cc, &gc->clientq, group_entry) {
|
TAILQ_FOREACH(cc, &gc->clientq, group_entry) {
|
||||||
|
12
xmalloc.c
12
xmalloc.c
@ -61,6 +61,18 @@ xcalloc(size_t no, size_t siz)
|
|||||||
return(p);
|
return(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
xreallocarray(void *ptr, size_t nmemb, size_t size)
|
||||||
|
{
|
||||||
|
void *p;
|
||||||
|
|
||||||
|
p = reallocarray(ptr, nmemb, size);
|
||||||
|
if (p == NULL)
|
||||||
|
errx(1, "xreallocarray: out of memory (new_size %zu bytes)",
|
||||||
|
nmemb * size);
|
||||||
|
return(p);
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
xstrdup(const char *str)
|
xstrdup(const char *str)
|
||||||
{
|
{
|
||||||
|
8
xutil.c
8
xutil.c
@ -220,7 +220,7 @@ xu_ewmh_net_client_list(struct screen_ctx *sc)
|
|||||||
if (i == 0)
|
if (i == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
winlist = xcalloc(i, sizeof(*winlist));
|
winlist = xreallocarray(NULL, i, sizeof(*winlist));
|
||||||
TAILQ_FOREACH(cc, &sc->clientq, entry)
|
TAILQ_FOREACH(cc, &sc->clientq, entry)
|
||||||
winlist[j++] = cc->win;
|
winlist[j++] = cc->win;
|
||||||
XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_CLIENT_LIST],
|
XChangeProperty(X_Dpy, sc->rootwin, ewmh[_NET_CLIENT_LIST],
|
||||||
@ -320,7 +320,7 @@ xu_ewmh_net_desktop_names(struct screen_ctx *sc)
|
|||||||
|
|
||||||
TAILQ_FOREACH(gc, &sc->groupq, entry)
|
TAILQ_FOREACH(gc, &sc->groupq, entry)
|
||||||
len += strlen(gc->name) + 1;
|
len += strlen(gc->name) + 1;
|
||||||
q = p = xcalloc(len, sizeof(*p));
|
q = p = xreallocarray(NULL, len, sizeof(*p));
|
||||||
|
|
||||||
tlen = len;
|
tlen = len;
|
||||||
TAILQ_FOREACH(gc, &sc->groupq, entry) {
|
TAILQ_FOREACH(gc, &sc->groupq, entry) {
|
||||||
@ -357,7 +357,7 @@ xu_ewmh_get_net_wm_state(struct client_ctx *cc, int *n)
|
|||||||
(unsigned char **)&p)) <= 0)
|
(unsigned char **)&p)) <= 0)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
state = xcalloc(*n, sizeof(Atom));
|
state = xreallocarray(NULL, *n, sizeof(Atom));
|
||||||
(void)memcpy(state, p, *n * sizeof(Atom));
|
(void)memcpy(state, p, *n * sizeof(Atom));
|
||||||
XFree((char *)p);
|
XFree((char *)p);
|
||||||
|
|
||||||
@ -444,7 +444,7 @@ xu_ewmh_set_net_wm_state(struct client_ctx *cc)
|
|||||||
int n, i, j;
|
int n, i, j;
|
||||||
|
|
||||||
oatoms = xu_ewmh_get_net_wm_state(cc, &n);
|
oatoms = xu_ewmh_get_net_wm_state(cc, &n);
|
||||||
atoms = xcalloc((n + _NET_WM_STATES_NITEMS), sizeof(Atom));
|
atoms = xreallocarray(NULL, (n + _NET_WM_STATES_NITEMS), sizeof(Atom));
|
||||||
for (i = j = 0; i < n; i++) {
|
for (i = j = 0; i < n; i++) {
|
||||||
if (oatoms[i] != ewmh[_NET_WM_STATE_STICKY] &&
|
if (oatoms[i] != ewmh[_NET_WM_STATE_STICKY] &&
|
||||||
oatoms[i] != ewmh[_NET_WM_STATE_MAXIMIZED_HORZ] &&
|
oatoms[i] != ewmh[_NET_WM_STATE_MAXIMIZED_HORZ] &&
|
||||||
|
Loading…
Reference in New Issue
Block a user