libi3: change scalloc() signature to match calloc()

This commit is contained in:
shdown 2015-08-03 12:50:13 +03:00
parent 05fb909636
commit bc52fae15c
32 changed files with 80 additions and 81 deletions

View File

@ -392,7 +392,7 @@ static char *rewrite_binding(const char *input) {
} }
} }
if (walk != beginning) { if (walk != beginning) {
char *str = scalloc(walk - beginning + 1); char *str = scalloc(walk - beginning + 1, 1);
/* We copy manually to handle escaping of characters. */ /* We copy manually to handle escaping of characters. */
int inpos, outpos; int inpos, outpos;
for (inpos = 0, outpos = 0; for (inpos = 0, outpos = 0;

View File

@ -77,7 +77,7 @@ static int reply_boolean_cb(void *params, int val) {
} }
static int reply_string_cb(void *params, const unsigned char *val, size_t len) { static int reply_string_cb(void *params, const unsigned char *val, size_t len) {
char *str = scalloc(len + 1); char *str = scalloc(len + 1, 1);
strncpy(str, (const char *)val, len); strncpy(str, (const char *)val, len);
if (strcmp(last_key, "error") == 0) if (strcmp(last_key, "error") == 0)
last_reply.error = str; last_reply.error = str;
@ -105,7 +105,7 @@ static int reply_end_map_cb(void *params) {
static int reply_map_key_cb(void *params, const unsigned char *keyVal, size_t keyLen) { static int reply_map_key_cb(void *params, const unsigned char *keyVal, size_t keyLen) {
free(last_key); free(last_key);
last_key = scalloc(keyLen + 1); last_key = scalloc(keyLen + 1, 1);
strncpy(last_key, (const char *)keyVal, keyLen); strncpy(last_key, (const char *)keyVal, keyLen);
return 1; return 1;
} }

View File

@ -105,13 +105,13 @@ __attribute__((format(printf, 1, 2))) static void set_statusline_error(const cha
va_start(args, format); va_start(args, format);
(void)vasprintf(&message, format, args); (void)vasprintf(&message, format, args);
struct status_block *err_block = scalloc(sizeof(struct status_block)); struct status_block *err_block = scalloc(1, sizeof(struct status_block));
err_block->full_text = i3string_from_utf8("Error: "); err_block->full_text = i3string_from_utf8("Error: ");
err_block->name = sstrdup("error"); err_block->name = sstrdup("error");
err_block->color = sstrdup("red"); err_block->color = sstrdup("red");
err_block->no_separator = true; err_block->no_separator = true;
struct status_block *message_block = scalloc(sizeof(struct status_block)); struct status_block *message_block = scalloc(1, sizeof(struct status_block));
message_block->full_text = i3string_from_utf8(message); message_block->full_text = i3string_from_utf8(message);
message_block->name = sstrdup("error_message"); message_block->name = sstrdup("error_message");
message_block->color = sstrdup("red"); message_block->color = sstrdup("red");
@ -433,7 +433,7 @@ void stdin_io_first_line_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
} else { } else {
/* In case of plaintext, we just add a single block and change its /* In case of plaintext, we just add a single block and change its
* full_text pointer later. */ * full_text pointer later. */
struct status_block *new_block = scalloc(sizeof(struct status_block)); struct status_block *new_block = scalloc(1, sizeof(struct status_block));
TAILQ_INSERT_TAIL(&statusline_head, new_block, blocks); TAILQ_INSERT_TAIL(&statusline_head, new_block, blocks);
read_flat_input((char *)buffer, rec); read_flat_input((char *)buffer, rec);
} }

View File

@ -146,7 +146,7 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
* users updating from that version and restarting i3bar before i3. */ * users updating from that version and restarting i3bar before i3. */
if (!strcmp(cur_key, "wheel_up_cmd")) { if (!strcmp(cur_key, "wheel_up_cmd")) {
DLOG("wheel_up_cmd = %.*s\n", len, val); DLOG("wheel_up_cmd = %.*s\n", len, val);
binding_t *binding = scalloc(sizeof(binding_t)); binding_t *binding = scalloc(1, sizeof(binding_t));
binding->input_code = 4; binding->input_code = 4;
sasprintf(&(binding->command), "%.*s", len, val); sasprintf(&(binding->command), "%.*s", len, val);
TAILQ_INSERT_TAIL(&(config.bindings), binding, bindings); TAILQ_INSERT_TAIL(&(config.bindings), binding, bindings);
@ -157,7 +157,7 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
* users updating from that version and restarting i3bar before i3. */ * users updating from that version and restarting i3bar before i3. */
if (!strcmp(cur_key, "wheel_down_cmd")) { if (!strcmp(cur_key, "wheel_down_cmd")) {
DLOG("wheel_down_cmd = %.*s\n", len, val); DLOG("wheel_down_cmd = %.*s\n", len, val);
binding_t *binding = scalloc(sizeof(binding_t)); binding_t *binding = scalloc(1, sizeof(binding_t));
binding->input_code = 5; binding->input_code = 5;
sasprintf(&(binding->command), "%.*s", len, val); sasprintf(&(binding->command), "%.*s", len, val);
TAILQ_INSERT_TAIL(&(config.bindings), binding, bindings); TAILQ_INSERT_TAIL(&(config.bindings), binding, bindings);
@ -277,7 +277,7 @@ static int config_boolean_cb(void *params_, int val) {
static int config_integer_cb(void *params_, long long val) { static int config_integer_cb(void *params_, long long val) {
if (parsing_bindings) { if (parsing_bindings) {
if (strcmp(cur_key, "input_code") == 0) { if (strcmp(cur_key, "input_code") == 0) {
binding_t *binding = scalloc(sizeof(binding_t)); binding_t *binding = scalloc(1, sizeof(binding_t));
binding->input_code = val; binding->input_code = val;
TAILQ_INSERT_TAIL(&(config.bindings), binding, bindings); TAILQ_INSERT_TAIL(&(config.bindings), binding, bindings);

View File

@ -533,7 +533,7 @@ void handle_button(xcb_button_press_event_t *event) {
} }
const size_t len = namelen + strlen("workspace \"\"") + 1; const size_t len = namelen + strlen("workspace \"\"") + 1;
char *buffer = scalloc(len + num_quotes); char *buffer = scalloc(len + num_quotes, 1);
strncpy(buffer, "workspace \"", strlen("workspace \"")); strncpy(buffer, "workspace \"", strlen("workspace \""));
size_t inpos, outpos; size_t inpos, outpos;
for (inpos = 0, outpos = strlen("workspace \""); for (inpos = 0, outpos = strlen("workspace \"");
@ -730,7 +730,7 @@ static void handle_client_message(xcb_client_message_event_t *event) {
values); values);
/* send the XEMBED_EMBEDDED_NOTIFY message */ /* send the XEMBED_EMBEDDED_NOTIFY message */
void *event = scalloc(32); void *event = scalloc(32, 1);
xcb_client_message_event_t *ev = event; xcb_client_message_event_t *ev = event;
ev->response_type = XCB_CLIENT_MESSAGE; ev->response_type = XCB_CLIENT_MESSAGE;
ev->window = client; ev->window = client;

View File

@ -111,7 +111,7 @@ void *smalloc(size_t size);
* there is no more memory available) * there is no more memory available)
* *
*/ */
void *scalloc(size_t size); void *scalloc(size_t num, size_t size);
/** /**
* Safe-wrapper around realloc which exits if realloc returns NULL (meaning * Safe-wrapper around realloc which exits if realloc returns NULL (meaning

View File

@ -23,7 +23,7 @@ void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window
/* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes. /* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes.
* In order to properly initialize these bytes, we allocate 32 bytes even * In order to properly initialize these bytes, we allocate 32 bytes even
* though we only need less for an xcb_configure_notify_event_t */ * though we only need less for an xcb_configure_notify_event_t */
void *event = scalloc(32); void *event = scalloc(32, 1);
xcb_configure_notify_event_t *generated_event = event; xcb_configure_notify_event_t *generated_event = event;
generated_event->event = window; generated_event->event = window;

View File

@ -34,7 +34,7 @@ char *resolve_tilde(const char *path) {
err(EXIT_FAILURE, "glob() failed"); err(EXIT_FAILURE, "glob() failed");
} else { } else {
head = globbuf.gl_pathv[0]; head = globbuf.gl_pathv[0];
result = scalloc(strlen(head) + (tail ? strlen(tail) : 0) + 1); result = scalloc(strlen(head) + (tail ? strlen(tail) : 0) + 1, 1);
strncpy(result, head, strlen(head)); strncpy(result, head, strlen(head));
if (tail) if (tail)
strncat(result, tail, strlen(tail)); strncat(result, tail, strlen(tail));

View File

@ -27,10 +27,10 @@ void *smalloc(size_t size) {
return result; return result;
} }
void *scalloc(size_t size) { void *scalloc(size_t num, size_t size) {
void *result = calloc(size, 1); void *result = calloc(num, size);
if (result == NULL) if (result == NULL)
err(EXIT_FAILURE, "calloc(%zd)", size); err(EXIT_FAILURE, "calloc(%zd, %zd)", num, size);
return result; return result;
} }

View File

@ -33,7 +33,7 @@ struct _i3String {
* *
*/ */
i3String *i3string_from_utf8(const char *from_utf8) { i3String *i3string_from_utf8(const char *from_utf8) {
i3String *str = scalloc(sizeof(i3String)); i3String *str = scalloc(1, sizeof(i3String));
/* Get the text */ /* Get the text */
str->utf8 = sstrdup(from_utf8); str->utf8 = sstrdup(from_utf8);
@ -64,10 +64,10 @@ i3String *i3string_from_markup(const char *from_markup) {
* *
*/ */
i3String *i3string_from_utf8_with_length(const char *from_utf8, size_t num_bytes) { i3String *i3string_from_utf8_with_length(const char *from_utf8, size_t num_bytes) {
i3String *str = scalloc(sizeof(i3String)); i3String *str = scalloc(1, sizeof(i3String));
/* Copy the actual text to our i3String */ /* Copy the actual text to our i3String */
str->utf8 = scalloc(sizeof(char) * (num_bytes + 1)); str->utf8 = scalloc(num_bytes + 1, 1);
strncpy(str->utf8, from_utf8, num_bytes); strncpy(str->utf8, from_utf8, num_bytes);
str->utf8[num_bytes] = '\0'; str->utf8[num_bytes] = '\0';
@ -97,12 +97,11 @@ i3String *i3string_from_markup_with_length(const char *from_markup, size_t num_b
* *
*/ */
i3String *i3string_from_ucs2(const xcb_char2b_t *from_ucs2, size_t num_glyphs) { i3String *i3string_from_ucs2(const xcb_char2b_t *from_ucs2, size_t num_glyphs) {
i3String *str = scalloc(sizeof(i3String)); i3String *str = scalloc(1, sizeof(i3String));
/* Copy the actual text to our i3String */ /* Copy the actual text to our i3String */
size_t num_bytes = num_glyphs * sizeof(xcb_char2b_t); str->ucs2 = scalloc(num_glyphs, sizeof(xcb_char2b_t));
str->ucs2 = scalloc(num_bytes); memcpy(str->ucs2, from_ucs2, num_glyphs * sizeof(xcb_char2b_t));
memcpy(str->ucs2, from_ucs2, num_bytes);
/* Store the length */ /* Store the length */
str->num_glyphs = num_glyphs; str->num_glyphs = num_glyphs;

View File

@ -23,8 +23,8 @@ static iconv_t ucs2_conversion_descriptor = (iconv_t)-1;
*/ */
char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs) { char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs) {
/* Allocate the output buffer (UTF-8 is at most 4 bytes per glyph) */ /* Allocate the output buffer (UTF-8 is at most 4 bytes per glyph) */
size_t buffer_size = num_glyphs * 4 * sizeof(char) + 1; size_t buffer_size = num_glyphs * 4 + 1;
char *buffer = scalloc(buffer_size); char *buffer = scalloc(buffer_size, 1);
/* We need to use an additional pointer, because iconv() modifies it */ /* We need to use an additional pointer, because iconv() modifies it */
char *output = buffer; char *output = buffer;

View File

@ -33,9 +33,9 @@ static struct Mode *mode_from_name(const char *name) {
} }
/* If the mode was not found, create a new one */ /* If the mode was not found, create a new one */
mode = scalloc(sizeof(struct Mode)); mode = scalloc(1, sizeof(struct Mode));
mode->name = sstrdup(name); mode->name = sstrdup(name);
mode->bindings = scalloc(sizeof(struct bindings_head)); mode->bindings = scalloc(1, sizeof(struct bindings_head));
TAILQ_INIT(mode->bindings); TAILQ_INIT(mode->bindings);
SLIST_INSERT_HEAD(&modes, mode, modes); SLIST_INSERT_HEAD(&modes, mode, modes);
@ -51,7 +51,7 @@ static struct Mode *mode_from_name(const char *name) {
Binding *configure_binding(const char *bindtype, const char *modifiers, const char *input_code, Binding *configure_binding(const char *bindtype, const char *modifiers, const char *input_code,
const char *release, const char *border, const char *whole_window, const char *release, const char *border, const char *whole_window,
const char *command, const char *modename) { const char *command, const char *modename) {
Binding *new_binding = scalloc(sizeof(Binding)); Binding *new_binding = scalloc(1, sizeof(Binding));
DLOG("bindtype %s, modifiers %s, input code %s, release %s\n", bindtype, modifiers, input_code, release); DLOG("bindtype %s, modifiers %s, input code %s, release %s\n", bindtype, modifiers, input_code, release);
new_binding->release = (release != NULL ? B_UPON_KEYRELEASE : B_UPON_KEYPRESS); new_binding->release = (release != NULL ? B_UPON_KEYRELEASE : B_UPON_KEYPRESS);
new_binding->border = (border != NULL); new_binding->border = (border != NULL);

View File

@ -243,7 +243,7 @@ char *parse_string(const char **walk, bool as_word) {
if (*walk == beginning) if (*walk == beginning)
return NULL; return NULL;
char *str = scalloc(*walk - beginning + 1); char *str = scalloc(*walk - beginning + 1, 1);
/* We copy manually to handle escaping of characters. */ /* We copy manually to handle escaping of characters. */
int inpos, outpos; int inpos, outpos;
for (inpos = 0, outpos = 0; for (inpos = 0, outpos = 0;
@ -270,7 +270,7 @@ char *parse_string(const char **walk, bool as_word) {
CommandResult *parse_command(const char *input, yajl_gen gen) { CommandResult *parse_command(const char *input, yajl_gen gen) {
DLOG("COMMAND: *%s*\n", input); DLOG("COMMAND: *%s*\n", input);
state = INITIAL; state = INITIAL;
CommandResult *result = scalloc(sizeof(CommandResult)); CommandResult *result = scalloc(1, sizeof(CommandResult));
/* A YAJL JSON generator used for formatting replies. */ /* A YAJL JSON generator used for formatting replies. */
command_output.json_gen = gen; command_output.json_gen = gen;

View File

@ -36,7 +36,7 @@ void con_force_split_parents_redraw(Con *con) {
* *
*/ */
Con *con_new_skeleton(Con *parent, i3Window *window) { Con *con_new_skeleton(Con *parent, i3Window *window) {
Con *new = scalloc(sizeof(Con)); Con *new = scalloc(1, sizeof(Con));
new->on_remove_child = con_on_remove_child; new->on_remove_child = con_on_remove_child;
TAILQ_INSERT_TAIL(&all_cons, new, all_cons); TAILQ_INSERT_TAIL(&all_cons, new, all_cons);
new->aspect_ratio = 0.0; new->aspect_ratio = 0.0;

View File

@ -58,7 +58,7 @@ bool parse_configuration(const char *override_configpath, bool use_nagbar) {
/* initialize default bindings if we're just validating the config file */ /* initialize default bindings if we're just validating the config file */
if (!use_nagbar && bindings == NULL) { if (!use_nagbar && bindings == NULL) {
bindings = scalloc(sizeof(struct bindings_head)); bindings = scalloc(1, sizeof(struct bindings_head));
TAILQ_INIT(bindings); TAILQ_INIT(bindings);
} }
@ -155,9 +155,9 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath,
SLIST_INIT(&modes); SLIST_INIT(&modes);
struct Mode *default_mode = scalloc(sizeof(struct Mode)); struct Mode *default_mode = scalloc(1, sizeof(struct Mode));
default_mode->name = sstrdup("default"); default_mode->name = sstrdup("default");
default_mode->bindings = scalloc(sizeof(struct bindings_head)); default_mode->bindings = scalloc(1, sizeof(struct bindings_head));
TAILQ_INIT(default_mode->bindings); TAILQ_INIT(default_mode->bindings);
SLIST_INSERT_HEAD(&modes, default_mode, modes); SLIST_INSERT_HEAD(&modes, default_mode, modes);

View File

@ -242,7 +242,7 @@ CFGFUN(for_window, const char *command) {
return; return;
} }
DLOG("\t should execute command %s for the criteria mentioned above\n", command); DLOG("\t should execute command %s for the criteria mentioned above\n", command);
Assignment *assignment = scalloc(sizeof(Assignment)); Assignment *assignment = scalloc(1, sizeof(Assignment));
assignment->type = A_COMMAND; assignment->type = A_COMMAND;
match_copy(&(assignment->match), current_match); match_copy(&(assignment->match), current_match);
assignment->dest.command = sstrdup(command); assignment->dest.command = sstrdup(command);
@ -400,7 +400,7 @@ CFGFUN(workspace, const char *workspace, const char *output) {
} }
} }
if (!duplicate) { if (!duplicate) {
assignment = scalloc(sizeof(struct Workspace_Assignment)); assignment = scalloc(1, sizeof(struct Workspace_Assignment));
assignment->name = sstrdup(workspace); assignment->name = sstrdup(workspace);
assignment->output = sstrdup(output); assignment->output = sstrdup(output);
TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments); TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
@ -458,7 +458,7 @@ CFGFUN(assign, const char *workspace) {
return; return;
} }
DLOG("New assignment, using above criteria, to workspace \"%s\".\n", workspace); DLOG("New assignment, using above criteria, to workspace \"%s\".\n", workspace);
Assignment *assignment = scalloc(sizeof(Assignment)); Assignment *assignment = scalloc(1, sizeof(Assignment));
match_copy(&(assignment->match), current_match); match_copy(&(assignment->match), current_match);
assignment->type = A_TO_WORKSPACE; assignment->type = A_TO_WORKSPACE;
assignment->dest.workspace = sstrdup(workspace); assignment->dest.workspace = sstrdup(workspace);
@ -472,7 +472,7 @@ CFGFUN(no_focus) {
} }
DLOG("New assignment, using above criteria, to ignore focus on manage.\n"); DLOG("New assignment, using above criteria, to ignore focus on manage.\n");
Assignment *assignment = scalloc(sizeof(Assignment)); Assignment *assignment = scalloc(1, sizeof(Assignment));
match_copy(&(assignment->match), current_match); match_copy(&(assignment->match), current_match);
assignment->type = A_NO_FOCUS; assignment->type = A_NO_FOCUS;
TAILQ_INSERT_TAIL(&assignments, assignment, assignments); TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
@ -555,7 +555,7 @@ static void bar_configure_binding(const char *button, const char *command) {
} }
} }
struct Barbinding *new_binding = scalloc(sizeof(struct Barbinding)); struct Barbinding *new_binding = scalloc(1, sizeof(struct Barbinding));
new_binding->input_code = input_code; new_binding->input_code = input_code;
new_binding->command = sstrdup(command); new_binding->command = sstrdup(command);
TAILQ_INSERT_TAIL(&(current_bar.bar_bindings), new_binding, bindings); TAILQ_INSERT_TAIL(&(current_bar.bar_bindings), new_binding, bindings);
@ -669,7 +669,7 @@ CFGFUN(bar_finish) {
/* Copy the current (static) structure into a dynamically allocated /* Copy the current (static) structure into a dynamically allocated
* one, then cleanup our static one. */ * one, then cleanup our static one. */
Barconfig *bar_config = scalloc(sizeof(Barconfig)); Barconfig *bar_config = scalloc(1, sizeof(Barconfig));
memcpy(bar_config, &current_bar, sizeof(Barconfig)); memcpy(bar_config, &current_bar, sizeof(Barconfig));
TAILQ_INSERT_TAIL(&barconfigs, bar_config, configs); TAILQ_INSERT_TAIL(&barconfigs, bar_config, configs);

View File

@ -414,7 +414,7 @@ struct ConfigResultIR *parse_config(const char *input, struct context *context)
} }
} }
if (walk != beginning) { if (walk != beginning) {
char *str = scalloc(walk - beginning + 1); char *str = scalloc(walk - beginning + 1, 1);
/* We copy manually to handle escaping of characters. */ /* We copy manually to handle escaping of characters. */
int inpos, outpos; int inpos, outpos;
for (inpos = 0, outpos = 0; for (inpos = 0, outpos = 0;
@ -519,7 +519,7 @@ struct ConfigResultIR *parse_config(const char *input, struct context *context)
/* Contains the same amount of characters as 'input' has, but with /* Contains the same amount of characters as 'input' has, but with
* the unparseable part highlighted using ^ characters. */ * the unparseable part highlighted using ^ characters. */
char *position = scalloc(strlen(error_line) + 1); char *position = scalloc(strlen(error_line) + 1, 1);
const char *copywalk; const char *copywalk;
for (copywalk = error_line; for (copywalk = error_line;
*copywalk != '\n' && *copywalk != '\r' && *copywalk != '\0'; *copywalk != '\n' && *copywalk != '\r' && *copywalk != '\0';
@ -849,7 +849,7 @@ bool parse_file(const char *f, bool use_nagbar) {
if (fstat(fd, &stbuf) == -1) if (fstat(fd, &stbuf) == -1)
die("Could not fstat file: %s\n", strerror(errno)); die("Could not fstat file: %s\n", strerror(errno));
buf = scalloc((stbuf.st_size + 1) * sizeof(char)); buf = scalloc(stbuf.st_size + 1, 1);
if ((fstr = fdopen(fd, "r")) == NULL) if ((fstr = fdopen(fd, "r")) == NULL)
die("Could not fdopen: %s\n", strerror(errno)); die("Could not fdopen: %s\n", strerror(errno));
@ -897,7 +897,7 @@ bool parse_file(const char *f, bool use_nagbar) {
while (*v_value == '\t' || *v_value == ' ') while (*v_value == '\t' || *v_value == ' ')
v_value++; v_value++;
struct Variable *new = scalloc(sizeof(struct Variable)); struct Variable *new = scalloc(1, sizeof(struct Variable));
new->key = sstrdup(v_key); new->key = sstrdup(v_key);
new->value = sstrdup(v_value); new->value = sstrdup(v_value);
SLIST_INSERT_HEAD(&variables, new, variables); SLIST_INSERT_HEAD(&variables, new, variables);
@ -990,7 +990,7 @@ bool parse_file(const char *f, bool use_nagbar) {
} }
} }
context = scalloc(sizeof(struct context)); context = scalloc(1, sizeof(struct context));
context->filename = f; context->filename = f;
struct ConfigResultIR *config_output = parse_config(new, context); struct ConfigResultIR *config_output = parse_config(new, context);

View File

@ -49,7 +49,7 @@ void fake_outputs_init(const char *output_spec) {
new_output->rect.width = min(new_output->rect.width, width); new_output->rect.width = min(new_output->rect.width, width);
new_output->rect.height = min(new_output->rect.height, height); new_output->rect.height = min(new_output->rect.height, height);
} else { } else {
new_output = scalloc(sizeof(Output)); new_output = scalloc(1, sizeof(Output));
sasprintf(&(new_output->name), "fake-%d", num_screens); sasprintf(&(new_output->name), "fake-%d", num_screens);
DLOG("Created new fake output %s (%p)\n", new_output->name, new_output); DLOG("Created new fake output %s (%p)\n", new_output->name, new_output);
new_output->active = true; new_output->active = true;

View File

@ -760,7 +760,7 @@ static void handle_client_message(xcb_client_message_event_t *event) {
uint32_t rnd = event->data.data32[1]; uint32_t rnd = event->data.data32[1];
DLOG("[i3 sync protocol] Sending random value %d back to X11 window 0x%08x\n", rnd, window); DLOG("[i3 sync protocol] Sending random value %d back to X11 window 0x%08x\n", rnd, window);
void *reply = scalloc(32); void *reply = scalloc(32, 1);
xcb_client_message_event_t *ev = reply; xcb_client_message_event_t *ev = reply;
ev->response_type = XCB_CLIENT_MESSAGE; ev->response_type = XCB_CLIENT_MESSAGE;

View File

@ -84,7 +84,7 @@ void ipc_shutdown(void) {
IPC_HANDLER(command) { IPC_HANDLER(command) {
/* To get a properly terminated buffer, we copy /* To get a properly terminated buffer, we copy
* message_size bytes out of the buffer */ * message_size bytes out of the buffer */
char *command = scalloc(message_size + 1); char *command = scalloc(message_size + 1, 1);
strncpy(command, (const char *)message, message_size); strncpy(command, (const char *)message, message_size);
LOG("IPC: received: *%s*\n", command); LOG("IPC: received: *%s*\n", command);
yajl_gen gen = yajl_gen_alloc(NULL); yajl_gen gen = yajl_gen_alloc(NULL);
@ -855,7 +855,7 @@ IPC_HANDLER(get_bar_config) {
/* To get a properly terminated buffer, we copy /* To get a properly terminated buffer, we copy
* message_size bytes out of the buffer */ * message_size bytes out of the buffer */
char *bar_id = scalloc(message_size + 1); char *bar_id = scalloc(message_size + 1, 1);
strncpy(bar_id, (const char *)message, message_size); strncpy(bar_id, (const char *)message, message_size);
LOG("IPC: looking for config for bar ID \"%s\"\n", bar_id); LOG("IPC: looking for config for bar ID \"%s\"\n", bar_id);
Barconfig *current, *config = NULL; Barconfig *current, *config = NULL;
@ -903,7 +903,7 @@ static int add_subscription(void *extra, const unsigned char *s,
client->events = realloc(client->events, client->num_events * sizeof(char *)); client->events = realloc(client->events, client->num_events * sizeof(char *));
/* We copy the string because it is not null-terminated and strndup() /* We copy the string because it is not null-terminated and strndup()
* is missing on some BSD systems */ * is missing on some BSD systems */
client->events[event] = scalloc(len + 1); client->events[event] = scalloc(len + 1, 1);
memcpy(client->events[event], s, len); memcpy(client->events[event], s, len);
DLOG("client is now subscribed to:\n"); DLOG("client is now subscribed to:\n");
@ -1060,13 +1060,13 @@ void ipc_new_client(EV_P_ struct ev_io *w, int revents) {
set_nonblock(client); set_nonblock(client);
struct ev_io *package = scalloc(sizeof(struct ev_io)); struct ev_io *package = scalloc(1, sizeof(struct ev_io));
ev_io_init(package, ipc_receive_message, client, EV_READ); ev_io_init(package, ipc_receive_message, client, EV_READ);
ev_io_start(EV_A_ package); ev_io_start(EV_A_ package);
DLOG("IPC: new client connected on fd %d\n", w->fd); DLOG("IPC: new client connected on fd %d\n", w->fd);
ipc_client *new = scalloc(sizeof(ipc_client)); ipc_client *new = scalloc(1, sizeof(ipc_client));
new->fd = client; new->fd = client;
TAILQ_INSERT_TAIL(&all_clients, new, clients); TAILQ_INSERT_TAIL(&all_clients, new, clients);

View File

@ -167,7 +167,7 @@ static int json_end_array(void *ctx) {
static int json_key(void *ctx, const unsigned char *val, size_t len) { static int json_key(void *ctx, const unsigned char *val, size_t len) {
LOG("key: %.*s\n", (int)len, val); LOG("key: %.*s\n", (int)len, val);
FREE(last_key); FREE(last_key);
last_key = scalloc((len + 1) * sizeof(char)); last_key = scalloc(len + 1, 1);
memcpy(last_key, val, len); memcpy(last_key, val, len);
if (strcasecmp(last_key, "swallows") == 0) if (strcasecmp(last_key, "swallows") == 0)
parsing_swallows = true; parsing_swallows = true;
@ -209,10 +209,10 @@ static int json_string(void *ctx, const unsigned char *val, size_t len) {
free(sval); free(sval);
} else { } else {
if (strcasecmp(last_key, "name") == 0) { if (strcasecmp(last_key, "name") == 0) {
json_node->name = scalloc((len + 1) * sizeof(char)); json_node->name = scalloc(len + 1, 1);
memcpy(json_node->name, val, len); memcpy(json_node->name, val, len);
} else if (strcasecmp(last_key, "sticky_group") == 0) { } else if (strcasecmp(last_key, "sticky_group") == 0) {
json_node->sticky_group = scalloc((len + 1) * sizeof(char)); json_node->sticky_group = scalloc(len + 1, 1);
memcpy(json_node->sticky_group, val, len); memcpy(json_node->sticky_group, val, len);
LOG("sticky_group of this container is %s\n", json_node->sticky_group); LOG("sticky_group of this container is %s\n", json_node->sticky_group);
} else if (strcasecmp(last_key, "orientation") == 0) { } else if (strcasecmp(last_key, "orientation") == 0) {
@ -361,7 +361,7 @@ static int json_int(void *ctx, long long val) {
json_node->old_id = val; json_node->old_id = val;
if (parsing_focus) { if (parsing_focus) {
struct focus_mapping *focus_mapping = scalloc(sizeof(struct focus_mapping)); struct focus_mapping *focus_mapping = scalloc(1, sizeof(struct focus_mapping));
focus_mapping->old_id = val; focus_mapping->old_id = val;
TAILQ_INSERT_TAIL(&focus_mappings, focus_mapping, focus_mappings); TAILQ_INSERT_TAIL(&focus_mappings, focus_mapping, focus_mappings);
} }

View File

@ -635,7 +635,7 @@ int main(int argc, char *argv[]) {
if (ipc_socket == -1) { if (ipc_socket == -1) {
ELOG("Could not create the IPC socket, IPC disabled\n"); ELOG("Could not create the IPC socket, IPC disabled\n");
} else { } else {
struct ev_io *ipc_io = scalloc(sizeof(struct ev_io)); struct ev_io *ipc_io = scalloc(1, sizeof(struct ev_io));
ev_io_init(ipc_io, ipc_new_client, ipc_socket, EV_READ); ev_io_init(ipc_io, ipc_new_client, ipc_socket, EV_READ);
ev_io_start(main_loop, ipc_io); ev_io_start(main_loop, ipc_io);
} }
@ -663,7 +663,7 @@ int main(int argc, char *argv[]) {
ELOG("Could not disable FD_CLOEXEC on fd %d\n", fd); ELOG("Could not disable FD_CLOEXEC on fd %d\n", fd);
} }
struct ev_io *ipc_io = scalloc(sizeof(struct ev_io)); struct ev_io *ipc_io = scalloc(1, sizeof(struct ev_io));
ev_io_init(ipc_io, ipc_new_client, fd, EV_READ); ev_io_init(ipc_io, ipc_new_client, fd, EV_READ);
ev_io_start(main_loop, ipc_io); ev_io_start(main_loop, ipc_io);
} }
@ -679,9 +679,9 @@ int main(int argc, char *argv[]) {
ewmh_update_desktop_names(); ewmh_update_desktop_names();
ewmh_update_desktop_viewport(); ewmh_update_desktop_viewport();
struct ev_io *xcb_watcher = scalloc(sizeof(struct ev_io)); struct ev_io *xcb_watcher = scalloc(1, sizeof(struct ev_io));
xcb_check = scalloc(sizeof(struct ev_check)); xcb_check = scalloc(1, sizeof(struct ev_check));
struct ev_prepare *xcb_prepare = scalloc(sizeof(struct ev_prepare)); struct ev_prepare *xcb_prepare = scalloc(1, sizeof(struct ev_prepare));
ev_io_init(xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ); ev_io_init(xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ);
ev_io_start(main_loop, xcb_watcher); ev_io_start(main_loop, xcb_watcher);

View File

@ -164,7 +164,7 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
DLOG("Managing window 0x%08x\n", window); DLOG("Managing window 0x%08x\n", window);
i3Window *cwindow = scalloc(sizeof(i3Window)); i3Window *cwindow = scalloc(1, sizeof(i3Window));
cwindow->id = window; cwindow->id = window;
cwindow->depth = get_visual_depth(attr->visual); cwindow->depth = get_visual_depth(attr->visual);

View File

@ -227,7 +227,7 @@ Output *get_output_next(direction_t direction, Output *current, output_close_far
void disable_randr(xcb_connection_t *conn) { void disable_randr(xcb_connection_t *conn) {
DLOG("RandR extension unusable, disabling.\n"); DLOG("RandR extension unusable, disabling.\n");
Output *s = scalloc(sizeof(Output)); Output *s = scalloc(1, sizeof(Output));
s->active = true; s->active = true;
s->rect.x = 0; s->rect.x = 0;
@ -292,7 +292,7 @@ void output_init_con(Output *output) {
topdock->type = CT_DOCKAREA; topdock->type = CT_DOCKAREA;
topdock->layout = L_DOCKAREA; topdock->layout = L_DOCKAREA;
/* this container swallows dock clients */ /* this container swallows dock clients */
Match *match = scalloc(sizeof(Match)); Match *match = scalloc(1, sizeof(Match));
match_init(match); match_init(match);
match->dock = M_DOCK_TOP; match->dock = M_DOCK_TOP;
match->insert_where = M_BELOW; match->insert_where = M_BELOW;
@ -326,7 +326,7 @@ void output_init_con(Output *output) {
bottomdock->type = CT_DOCKAREA; bottomdock->type = CT_DOCKAREA;
bottomdock->layout = L_DOCKAREA; bottomdock->layout = L_DOCKAREA;
/* this container swallows dock clients */ /* this container swallows dock clients */
match = scalloc(sizeof(Match)); match = scalloc(1, sizeof(Match));
match_init(match); match_init(match);
match->dock = M_DOCK_BOTTOM; match->dock = M_DOCK_BOTTOM;
match->insert_where = M_BELOW; match->insert_where = M_BELOW;
@ -522,7 +522,7 @@ static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id,
Output *new = get_output_by_id(id); Output *new = get_output_by_id(id);
bool existing = (new != NULL); bool existing = (new != NULL);
if (!existing) if (!existing)
new = scalloc(sizeof(Output)); new = scalloc(1, sizeof(Output));
new->id = id; new->id = id;
new->primary = (primary && primary->output == id); new->primary = (primary && primary->output == id);
FREE(new->name); FREE(new->name);

View File

@ -25,7 +25,7 @@ struct regex *regex_new(const char *pattern) {
const char *error; const char *error;
int errorcode, offset; int errorcode, offset;
struct regex *re = scalloc(sizeof(struct regex)); struct regex *re = scalloc(1, sizeof(struct regex));
re->pattern = sstrdup(pattern); re->pattern = sstrdup(pattern);
int options = PCRE_UTF8; int options = PCRE_UTF8;
#ifdef PCRE_HAS_UCP #ifdef PCRE_HAS_UCP

View File

@ -109,9 +109,9 @@ void restore_connect(void) {
if (restore_conn == NULL || xcb_connection_has_error(restore_conn)) if (restore_conn == NULL || xcb_connection_has_error(restore_conn))
errx(EXIT_FAILURE, "Cannot open display\n"); errx(EXIT_FAILURE, "Cannot open display\n");
xcb_watcher = scalloc(sizeof(struct ev_io)); xcb_watcher = scalloc(1, sizeof(struct ev_io));
xcb_check = scalloc(sizeof(struct ev_check)); xcb_check = scalloc(1, sizeof(struct ev_check));
xcb_prepare = scalloc(sizeof(struct ev_prepare)); xcb_prepare = scalloc(1, sizeof(struct ev_prepare));
ev_io_init(xcb_watcher, restore_xcb_got_event, xcb_get_file_descriptor(restore_conn), EV_READ); ev_io_init(xcb_watcher, restore_xcb_got_event, xcb_get_file_descriptor(restore_conn), EV_READ);
ev_io_start(main_loop, xcb_watcher); ev_io_start(main_loop, xcb_watcher);
@ -210,7 +210,7 @@ static void open_placeholder_window(Con *con) {
DLOG("Created placeholder window 0x%08x for leaf container %p / %s\n", DLOG("Created placeholder window 0x%08x for leaf container %p / %s\n",
placeholder, con, con->name); placeholder, con, con->name);
placeholder_state *state = scalloc(sizeof(placeholder_state)); placeholder_state *state = scalloc(1, sizeof(placeholder_state));
state->window = placeholder; state->window = placeholder;
state->con = con; state->con = con;
state->rect = con->rect; state->rect = con->rect;

View File

@ -149,7 +149,7 @@ void start_application(const char *command, bool no_startup_id) {
free(first_word); free(first_word);
/* Trigger a timeout after 60 seconds */ /* Trigger a timeout after 60 seconds */
struct ev_timer *timeout = scalloc(sizeof(struct ev_timer)); struct ev_timer *timeout = scalloc(1, sizeof(struct ev_timer));
ev_timer_init(timeout, startup_timeout, 60.0, 0.); ev_timer_init(timeout, startup_timeout, 60.0, 0.);
timeout->data = context; timeout->data = context;
ev_timer_start(main_loop, timeout); ev_timer_start(main_loop, timeout);
@ -159,7 +159,7 @@ void start_application(const char *command, bool no_startup_id) {
/* Save the ID and current workspace in our internal list of startup /* Save the ID and current workspace in our internal list of startup
* sequences */ * sequences */
Con *ws = con_get_workspace(focused); Con *ws = con_get_workspace(focused);
struct Startup_Sequence *sequence = scalloc(sizeof(struct Startup_Sequence)); struct Startup_Sequence *sequence = scalloc(1, sizeof(struct Startup_Sequence));
sequence->id = sstrdup(sn_launcher_context_get_startup_id(context)); sequence->id = sstrdup(sn_launcher_context_get_startup_id(context));
sequence->workspace = sstrdup(ws->name); sequence->workspace = sstrdup(ws->name);
sequence->context = context; sequence->context = context;

View File

@ -276,7 +276,7 @@ void i3_restart(bool forget_layout) {
int num_args; int num_args;
for (num_args = 0; start_argv[num_args] != NULL; num_args++) for (num_args = 0; start_argv[num_args] != NULL; num_args++)
; ;
char **new_argv = scalloc((num_args + 3) * sizeof(char *)); char **new_argv = scalloc(num_args + 3, sizeof(char *));
/* copy the arguments, but skip the ones we'll replace */ /* copy the arguments, but skip the ones we'll replace */
int write_index = 0; int write_index = 0;

View File

@ -397,7 +397,7 @@ static void _workspace_show(Con *workspace) {
if (focused->urgency_timer == NULL) { if (focused->urgency_timer == NULL) {
DLOG("Deferring reset of urgency flag of con %p on newly shown workspace %p\n", DLOG("Deferring reset of urgency flag of con %p on newly shown workspace %p\n",
focused, workspace); focused, workspace);
focused->urgency_timer = scalloc(sizeof(struct ev_timer)); focused->urgency_timer = scalloc(1, sizeof(struct ev_timer));
/* use a repeating timer to allow for easy resets */ /* use a repeating timer to allow for easy resets */
ev_timer_init(focused->urgency_timer, workspace_defer_update_urgent_hint_cb, ev_timer_init(focused->urgency_timer, workspace_defer_update_urgent_hint_cb,
config.workspace_urgency_timer, config.workspace_urgency_timer); config.workspace_urgency_timer, config.workspace_urgency_timer);

View File

@ -147,7 +147,7 @@ void x_con_init(Con *con, uint16_t depth) {
if (win_colormap != XCB_NONE) if (win_colormap != XCB_NONE)
xcb_free_colormap(conn, win_colormap); xcb_free_colormap(conn, win_colormap);
struct con_state *state = scalloc(sizeof(struct con_state)); struct con_state *state = scalloc(1, sizeof(struct con_state));
state->id = con->frame; state->id = con->frame;
state->mapped = false; state->mapped = false;
state->initial = true; state->initial = true;
@ -286,7 +286,7 @@ void x_window_kill(xcb_window_t window, kill_window_t kill_window) {
/* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes. /* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes.
* In order to properly initialize these bytes, we allocate 32 bytes even * In order to properly initialize these bytes, we allocate 32 bytes even
* though we only need less for an xcb_configure_notify_event_t */ * though we only need less for an xcb_configure_notify_event_t */
void *event = scalloc(32); void *event = scalloc(32, 1);
xcb_client_message_event_t *ev = event; xcb_client_message_event_t *ev = event;
ev->response_type = XCB_CLIENT_MESSAGE; ev->response_type = XCB_CLIENT_MESSAGE;
@ -376,7 +376,7 @@ void x_draw_decoration(Con *con) {
return; return;
/* 1: build deco_params and compare with cache */ /* 1: build deco_params and compare with cache */
struct deco_render_params *p = scalloc(sizeof(struct deco_render_params)); struct deco_render_params *p = scalloc(1, sizeof(struct deco_render_params));
/* find out which colors to use */ /* find out which colors to use */
if (con->urgent) if (con->urgent)

View File

@ -114,7 +114,7 @@ void send_take_focus(xcb_window_t window, xcb_timestamp_t timestamp) {
/* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes. /* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes.
* In order to properly initialize these bytes, we allocate 32 bytes even * In order to properly initialize these bytes, we allocate 32 bytes even
* though we only need less for an xcb_configure_notify_event_t */ * though we only need less for an xcb_configure_notify_event_t */
void *event = scalloc(32); void *event = scalloc(32, 1);
xcb_client_message_event_t *ev = event; xcb_client_message_event_t *ev = event;
ev->response_type = XCB_CLIENT_MESSAGE; ev->response_type = XCB_CLIENT_MESSAGE;

View File

@ -56,7 +56,7 @@ static void query_screens(xcb_connection_t *conn) {
s->rect.width = min(s->rect.width, screen_info[screen].width); s->rect.width = min(s->rect.width, screen_info[screen].width);
s->rect.height = min(s->rect.height, screen_info[screen].height); s->rect.height = min(s->rect.height, screen_info[screen].height);
} else { } else {
s = scalloc(sizeof(Output)); s = scalloc(1, sizeof(Output));
sasprintf(&(s->name), "xinerama-%d", num_screens); sasprintf(&(s->name), "xinerama-%d", num_screens);
DLOG("Created new Xinerama screen %s (%p)\n", s->name, s); DLOG("Created new Xinerama screen %s (%p)\n", s->name, s);
s->active = true; s->active = true;