add memory allocation assertions
This commit is contained in:
parent
38c124b772
commit
d9d071344d
@ -66,6 +66,7 @@ Client* wm_client_create(Wm *wm, Window w)
|
||||
XGetWMName(wm->display, w, &xtp);
|
||||
|
||||
Client *c = calloc(1, sizeof(Client));
|
||||
assert(c);
|
||||
|
||||
c->next = NULL;
|
||||
c->prev = NULL;
|
||||
@ -81,6 +82,7 @@ Client* wm_client_create(Wm *wm, Window w)
|
||||
strln = strlen((char*)xtp.value);
|
||||
DEBUG_PRINT("%s allocating %d bytes for c->name\n", __func__, strln)
|
||||
c->name = malloc(strln+1);
|
||||
assert(c->name);
|
||||
strcpy(c->name, (char*)xtp.value);
|
||||
}
|
||||
|
||||
|
10
src/config.c
10
src/config.c
@ -26,10 +26,12 @@ void wm_keybinds_init_def(Config *config)
|
||||
{
|
||||
char *st[] = {"st", NULL};
|
||||
char **sth = malloc(sizeof(st));
|
||||
assert(sth);
|
||||
memcpy(sth, st, sizeof(st));
|
||||
|
||||
char *dmenu[] = {"i3-dmenu-desktop", NULL};
|
||||
char **dmenuh = malloc(sizeof(dmenu));
|
||||
assert(dmenuh);
|
||||
memcpy(dmenuh, dmenu, sizeof(dmenu));
|
||||
int size;
|
||||
|
||||
@ -139,6 +141,7 @@ void wm_keybinds_init_def(Config *config)
|
||||
config->kb_count = size / sizeof(Keybind);
|
||||
DEBUG_PRINT("sizeof k: %d\n", size);
|
||||
config->keybinds = malloc(size);
|
||||
assert(config->keybinds);
|
||||
memcpy(config->keybinds, k, size);
|
||||
}
|
||||
|
||||
@ -178,6 +181,7 @@ void wm_configfile_init(ConfigFile *config, const char *filename)
|
||||
}
|
||||
|
||||
config->available_commands = calloc(config->command_count, sizeof(ConfigCommand));
|
||||
assert(config->available_commands);
|
||||
memcpy(config->available_commands, commands, sizeof(commands));
|
||||
}
|
||||
|
||||
@ -337,14 +341,20 @@ void wm_configcommand_init(ConfigCommand *command)
|
||||
|
||||
command->argv = calloc(CONFIG_ARGC_MAX, sizeof(void*));
|
||||
command->args = calloc(CONFIG_ARGC_MAX, sizeof(Arg));
|
||||
assert(command->argv);
|
||||
assert(command->args);
|
||||
|
||||
for (size_t i = 0; i < CONFIG_ARGC_MAX; i++) {
|
||||
command->argv[i] = calloc(CONFIG_ARGLEN_MAX, 1);
|
||||
command->args[i].s = calloc(CONFIG_ARGLEN_MAX, 1);
|
||||
command->args[i].sl = calloc(CONFIG_ARGC_MAX, sizeof(char*));
|
||||
assert(command->argv[i]);
|
||||
assert(command->args[i].s);
|
||||
assert(command->args[i].sl);
|
||||
|
||||
for (size_t j = 0; j < CONFIG_ARGC_MAX; j++) {
|
||||
command->args[i].sl[j] = calloc(CONFIG_ARGLEN_MAX, 1);
|
||||
assert(command->args[i].sl[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
src/util.c
10
src/util.c
@ -15,6 +15,7 @@ TreeNode* wm_treenode_new(NodeType type, TreeNode *parent)
|
||||
{
|
||||
DEBUG_PRINT("%s\n", __func__);
|
||||
TreeNode *node = calloc(sizeof(TreeNode), 1);
|
||||
assert(node);
|
||||
|
||||
node->parent = parent;
|
||||
node->type = type;
|
||||
@ -173,6 +174,7 @@ PtrArray wm_nonempty_workspaces_to_strptrarray(Wm *wm)
|
||||
TreeNode *node = wm->smon->workspaces[i].tree;
|
||||
if (!wm_treenode_is_empty(node) || (node->type == NODE_CLIENT && node->client)) {
|
||||
WmWorkspaceToStrRet *ws_str_with_index = malloc(sizeof(WmWorkspaceToStrRet));
|
||||
assert(ws_str_with_index);
|
||||
*ws_str_with_index = (WmWorkspaceToStrRet) {
|
||||
.ws_index = i,
|
||||
.str = wm_treenode_to_str(wm->smon->workspaces[i].tree)
|
||||
@ -266,6 +268,7 @@ NodeArray* wm_postorder_traversal(TreeNode *tree)
|
||||
while (root != NULL || stack->size > 0) {
|
||||
if (root != NULL) {
|
||||
NodeWithIndex *n = malloc(sizeof(NodeWithIndex));
|
||||
assert(n);
|
||||
n->node = root;
|
||||
n->index = root_index;
|
||||
wm_nodearray_push(stack, (void*)n);
|
||||
@ -558,9 +561,11 @@ TreeNode* wm_treenode_remove_client(Wm *wm, TreeNode *root, Client *client)
|
||||
NodeArray* wm_nodearray_new()
|
||||
{
|
||||
NodeArray *arr = calloc(1, sizeof(NodeArray));
|
||||
assert(arr);
|
||||
|
||||
arr->capacity = 10;
|
||||
arr->nodes = calloc(arr->capacity, sizeof(TreeNode*));
|
||||
assert(arr->nodes);
|
||||
arr->size = 0;
|
||||
|
||||
return arr;
|
||||
@ -574,12 +579,14 @@ void wm_nodearray_push(NodeArray *arr, TreeNode *node)
|
||||
|
||||
if (arr->size >= arr->capacity) {
|
||||
TreeNode* temp = calloc(arr->capacity, sizeof(TreeNode*));
|
||||
assert(temp);
|
||||
memcpy(temp, arr->nodes, arr->capacity * sizeof(TreeNode*));
|
||||
free(arr->nodes);
|
||||
size_t old_capacity = arr->capacity;
|
||||
arr->capacity = old_capacity * 2;
|
||||
|
||||
arr->nodes = calloc(arr->capacity, sizeof(TreeNode*));
|
||||
assert(arr->nodes);
|
||||
memcpy(arr->nodes, temp, old_capacity * sizeof(TreeNode*));
|
||||
|
||||
free(temp);
|
||||
@ -663,6 +670,7 @@ PtrArray wm_ptrarray_new()
|
||||
|
||||
arr.capacity = 10;
|
||||
arr.ptrs = calloc(arr.capacity, sizeof(void*));
|
||||
assert(arr.ptrs);
|
||||
arr.size = 0;
|
||||
|
||||
return arr;
|
||||
@ -676,12 +684,14 @@ void wm_ptrarray_push(PtrArray *arr, void* ptr)
|
||||
|
||||
if (arr->size >= arr->capacity) {
|
||||
void* temp = calloc(arr->capacity, sizeof(void*));
|
||||
assert(temp);
|
||||
memcpy(temp, arr->ptrs, arr->capacity * sizeof(void*));
|
||||
free(arr->ptrs);
|
||||
size_t old_capacity = arr->capacity;
|
||||
arr->capacity = old_capacity * 2;
|
||||
|
||||
arr->ptrs = calloc(arr->capacity, sizeof(void*));
|
||||
assert(arr->ptrs);
|
||||
memcpy(arr->ptrs, temp, old_capacity * sizeof(void*));
|
||||
|
||||
free(temp);
|
||||
|
2
src/wm.c
2
src/wm.c
@ -60,12 +60,14 @@ void wm_monitors_open_all(Wm *wm, Display *d)
|
||||
|
||||
wm->wm_mc = count;
|
||||
wm->monitors = malloc(count * sizeof(Monitor));
|
||||
assert(wm->monitors);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
wm->monitors[i] = wm_monitor_open(d, xsi[i]);
|
||||
//TODO: cfg
|
||||
wm->monitors[i].wscount = 9;
|
||||
wm->monitors[i].workspaces = calloc(wm->monitors[i].wscount, sizeof(Workspace));
|
||||
assert(wm->monitors[i].workspaces);
|
||||
wm->monitors[i].selws = 0;
|
||||
|
||||
for (size_t j = 0; j < wm->monitors[i].wscount; j++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user