Skip to content

Commit

Permalink
global: Replaced all instances of memset(p, 0, sizeof(*p)) with the n…
Browse files Browse the repository at this point in the history
…ew i_zero() macro.

Used the following script:

C_FILES=`git ls-files *.c`
H_FILES=`git ls-files *.h`
for F in "$C_FILES $H_FILES"; do
        echo "$F"
  perl -p -i -e 's/safe_memset\(&\(?([^,]*)\)?,\s*0,\s*sizeof\(\g1\)\)/i_zero_safe(&$1)/g' $F
  perl -p -i -e 's/safe_memset\(([^,]*),\s*0,\s*sizeof\(\*\g1\)\)/i_zero_safe($1)/g' $F
  perl -p -i -e 's/memset\(&\(?([^,]*)\)?,\s*0,\s*sizeof\(\g1\)\)/i_zero(&$1)/g' $F
  perl -p -i -e 's/memset\(([^,]*),\s*0,\s*sizeof\(\*\g1\)\)/i_zero($1)/g' $F
done
  • Loading branch information
stephanbosch committed Jan 11, 2017
1 parent b2fa20b commit 74d223d
Show file tree
Hide file tree
Showing 347 changed files with 689 additions and 689 deletions.
2 changes: 1 addition & 1 deletion src/auth/auth-request-var-expand.c
Expand Up @@ -246,7 +246,7 @@ void auth_request_var_expand_with_table(string_t *dest, const char *str,
{
struct auth_request_var_expand_ctx ctx;

memset(&ctx, 0, sizeof(ctx));
i_zero(&ctx);
ctx.auth_request = auth_request;
ctx.escape_func = escape_func == NULL ? escape_none : escape_func;
var_expand_with_funcs(dest, str, table,
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth-request.c
Expand Up @@ -2106,7 +2106,7 @@ static int auth_request_proxy_host_lookup(struct auth_request *request,
unsigned int secs;

/* need to do dns lookup for the host */
memset(&dns_set, 0, sizeof(dns_set));
i_zero(&dns_set);
dns_set.dns_client_socket_path = AUTH_DNS_SOCKET_PATH;
dns_set.timeout_msecs = AUTH_DNS_DEFAULT_TIMEOUT_MSECS;
value = auth_fields_find(request->extra_fields, "proxy_timeout");
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth-settings.c
Expand Up @@ -513,7 +513,7 @@ auth_settings_read(const char *service, pool_t pool,
const char *error;
void **sets;

memset(&input, 0, sizeof(input));
i_zero(&input);
input.roots = set_roots;
input.module = "auth";
input.service = service;
Expand Down
2 changes: 1 addition & 1 deletion src/auth/db-dict.c
Expand Up @@ -297,7 +297,7 @@ struct dict_connection *db_dict_init(const char *config_path)
p_array_init(&conn->set.parsed_passdb_objects, pool, 2);
p_array_init(&conn->set.parsed_userdb_objects, pool, 2);

memset(&ctx, 0, sizeof(ctx));
i_zero(&ctx);
ctx.conn = conn;
if (!settings_read(config_path, NULL, parse_setting,
parse_section, &ctx, &error))
Expand Down
8 changes: 4 additions & 4 deletions src/auth/db-ldap.c
Expand Up @@ -629,7 +629,7 @@ ldap_request_send_subquery(struct ldap_connection *conn,
struct ldap_field_find_subquery_context ctx;
string_t *tmp_str = t_str_new(64);

memset(&ctx, 0, sizeof(ctx));
i_zero(&ctx);
t_array_init(&ctx.attr_names, 8);
ctx.name = named_res->field->name;

Expand Down Expand Up @@ -904,7 +904,7 @@ static void ldap_input(struct ldap_connection *conn)
if (conn->ld == NULL)
return;

memset(&timeout, 0, sizeof(timeout));
i_zero(&timeout);
ret = ldap_result(conn->ld, LDAP_RES_ANY, 0, &timeout, &msg);
#ifdef OPENLDAP_ASYNC_WORKAROUND
if (ret == 0) {
Expand Down Expand Up @@ -999,7 +999,7 @@ static int db_ldap_bind_sasl(struct ldap_connection *conn)
struct db_ldap_sasl_bind_context context;
int ret;

memset(&context, 0, sizeof(context));
i_zero(&context);
context.authcid = conn->set.dn;
context.passwd = conn->set.dnpass;
context.realm = conn->set.sasl_realm;
Expand Down Expand Up @@ -1211,7 +1211,7 @@ int db_ldap_connect(struct ldap_connection *conn)

if (debug) {
if (gettimeofday(&start, NULL) < 0)
memset(&start, 0, sizeof(start));
i_zero(&start);
}
i_assert(conn->pending_count == 0);

Expand Down
4 changes: 2 additions & 2 deletions src/auth/main.c
Expand Up @@ -189,7 +189,7 @@ static void main_preinit(void)

services = read_global_settings();

memset(&mod_set, 0, sizeof(mod_set));
i_zero(&mod_set);
mod_set.abi_version = DOVECOT_ABI_VERSION;
mod_set.require_init_funcs = TRUE;
mod_set.debug = global_auth_settings->debug;
Expand Down Expand Up @@ -220,7 +220,7 @@ void auth_module_load(const char *names)
{
struct module_dir_load_settings mod_set;

memset(&mod_set, 0, sizeof(mod_set));
i_zero(&mod_set);
mod_set.abi_version = DOVECOT_ABI_VERSION;
mod_set.require_init_funcs = TRUE;
mod_set.debug = global_auth_settings->debug;
Expand Down
2 changes: 1 addition & 1 deletion src/auth/passdb-pam.c
Expand Up @@ -261,7 +261,7 @@ pam_verify_plain_call(struct auth_request *request, const char *service,
conv.conv = pam_userpass_conv;
conv.appdata_ptr = &ctx;

memset(&ctx, 0, sizeof(ctx));
i_zero(&ctx);
ctx.request = request;
ctx.pass = password;

Expand Down
2 changes: 1 addition & 1 deletion src/config/config-connection.c
Expand Up @@ -75,7 +75,7 @@ static int config_connection_request(struct config_connection *conn,

/* [<args>] */
t_array_init(&modules, 4);
memset(&filter, 0, sizeof(filter));
i_zero(&filter);
for (; *args != NULL; args++) {
if (strncmp(*args, "service=", 8) == 0)
filter.service = *args + 8;
Expand Down
2 changes: 1 addition & 1 deletion src/config/config-filter.c
Expand Up @@ -215,7 +215,7 @@ config_filter_find_all(struct config_filter_context *ctx, pool_t pool,
ARRAY_TYPE(const_string) service_names;
unsigned int i;

memset(output_r, 0, sizeof(*output_r));
i_zero(output_r);

p_array_init(&matches, pool, 8);
p_array_init(&service_names, pool, 8);
Expand Down
6 changes: 3 additions & 3 deletions src/config/config-parser.c
Expand Up @@ -967,7 +967,7 @@ int config_parse_file(const char *path, bool expand_values,
}
}

memset(&ctx, 0, sizeof(ctx));
i_zero(&ctx);
ctx.pool = pool_alloconly_create(MEMPOOL_GROWING"config file parser", 1024*256);
ctx.path = path;
ctx.hide_errors = fd == -1;
Expand All @@ -982,7 +982,7 @@ int config_parse_file(const char *path, bool expand_values,
settings_parser_flags);
}

memset(&root, 0, sizeof(root));
i_zero(&root);
root.path = path;
ctx.cur_input = &root;
ctx.expand_values = expand_values;
Expand Down Expand Up @@ -1052,7 +1052,7 @@ void config_parse_load_modules(void)
struct service_settings *const *services, *service_set;
unsigned int i, count;

memset(&mod_set, 0, sizeof(mod_set));
i_zero(&mod_set);
mod_set.abi_version = DOVECOT_ABI_VERSION;
modules = module_dir_load(CONFIG_MODULE_DIR, NULL, &mod_set);
module_dir_init(modules);
Expand Down
4 changes: 2 additions & 2 deletions src/config/doveconf.c
Expand Up @@ -608,7 +608,7 @@ static void hostname_verify_format(const char *arg)
const char *host2;
bool duplicates = FALSE;

memset(&fmt, 0, sizeof(fmt));
i_zero(&fmt);
if (arg != NULL) {
/* host%d, host%2d, host%02d */
p = strchr(arg, '%');
Expand Down Expand Up @@ -723,7 +723,7 @@ int main(int argc, char *argv[])
i_set_failure_exit_callback(failure_exit_callback);
}

memset(&filter, 0, sizeof(filter));
i_zero(&filter);
master_service = master_service_init("config",
MASTER_SERVICE_FLAG_STANDALONE,
&argc, &argv, "adf:hHm:nNpPexS");
Expand Down
4 changes: 2 additions & 2 deletions src/config/old-set-parser.c
Expand Up @@ -475,7 +475,7 @@ static bool old_auth_section(struct config_parser_context *ctx,
return FALSE;
}
ctx->old->seen_auth_section = TRUE;
memset(&ctx->old->socket_set, 0, sizeof(ctx->old->socket_set));
i_zero(&ctx->old->socket_set);

ctx->old->auth_section++;
if ((strcmp(key, "passdb") == 0 || strcmp(key, "userdb") == 0) &&
Expand Down Expand Up @@ -570,7 +570,7 @@ static void socket_apply(struct config_parser_context *ctx)
config_apply_line(ctx, "group",
t_strdup_printf("%s/group=%s", prefix, set->group), NULL);
}
memset(&ctx->old->socket_set, 0, sizeof(ctx->old->socket_set));
i_zero(&ctx->old->socket_set);
}

bool old_settings_handle(struct config_parser_context *ctx,
Expand Down
2 changes: 1 addition & 1 deletion src/dict/main.c
Expand Up @@ -106,7 +106,7 @@ static void main_init(void)
NULL));
}

memset(&mod_set, 0, sizeof(mod_set));
i_zero(&mod_set);
mod_set.abi_version = DOVECOT_ABI_VERSION;
mod_set.require_init_funcs = TRUE;

Expand Down
2 changes: 1 addition & 1 deletion src/director/login-connection.c
Expand Up @@ -206,7 +206,7 @@ static void auth_input_line(const char *line, void *context)
args++;
}

memset(&temp_request, 0, sizeof(temp_request));
i_zero(&temp_request);
for (; *args != NULL; args++) {
if (strncmp(*args, "proxy", 5) == 0 &&
((*args)[5] == '=' || (*args)[5] == '\0'))
Expand Down
2 changes: 1 addition & 1 deletion src/doveadm/client-connection-http.c
Expand Up @@ -328,7 +328,7 @@ doveadm_http_server_command_execute(struct client_connection_http *conn)
struct istream *is;
const char *user;
struct ioloop *ioloop,*prev_ioloop = current_ioloop;
memset(&cctx, 0, sizeof(cctx));
i_zero(&cctx);

// create iostream
doveadm_print_ostream = iostream_temp_create("/tmp/doveadm.", 0);
Expand Down
4 changes: 2 additions & 2 deletions src/doveadm/client-connection.c
Expand Up @@ -289,7 +289,7 @@ static bool client_handle_command(struct client_connection *conn, char **args)
i_error("doveadm client: No command given");
return FALSE;
}
memset(&cctx, 0, sizeof(cctx));
i_zero(&cctx);
cctx.cli = FALSE;
cctx.tcp_server = TRUE;

Expand Down Expand Up @@ -463,7 +463,7 @@ static int client_connection_read_settings(struct client_connection *conn)
const char *error;
void *set;

memset(&input, 0, sizeof(input));
i_zero(&input);
input.roots = set_roots;
input.service = "doveadm";
input.local_ip = conn->local_ip;
Expand Down
4 changes: 2 additions & 2 deletions src/doveadm/doveadm-auth-server.c
Expand Up @@ -295,7 +295,7 @@ cmd_user_mail_input(struct mail_storage_service_ctx *storage_service,
pool_t pool;
int ret;

memset(&service_input, 0, sizeof(service_input));
i_zero(&service_input);
service_input.module = "mail";
service_input.service = input->info.service;
service_input.username = input->username;
Expand Down Expand Up @@ -367,7 +367,7 @@ static void cmd_user_ver2(struct doveadm_cmd_context *cctx)
(void)doveadm_cmd_param_str(cctx, "field", &show_field);
(void)doveadm_cmd_param_bool(cctx, "userdb-only", &userdb_only);

memset(&input, 0, sizeof(input));
i_zero(&input);
if (doveadm_cmd_param_array(cctx, "auth-info", &optval))
for(;*optval != NULL; optval++)
auth_user_info_parse(&input.info, *optval);
Expand Down
8 changes: 4 additions & 4 deletions src/doveadm/doveadm-auth.c
Expand Up @@ -179,7 +179,7 @@ static void auth_connected(struct auth_client *client,
base64_resp = t_str_new(128);
base64_encode(str_data(init_resp), str_len(init_resp), base64_resp);

memset(&info, 0, sizeof(info));
i_zero(&info);
info.mech = "PLAIN";
info.service = input->info.service;
info.local_ip = input->info.local_ip;
Expand Down Expand Up @@ -295,7 +295,7 @@ static void cmd_auth_cache_flush(int argc, char *argv[])

static void authtest_input_init(struct authtest_input *input)
{
memset(input, 0, sizeof(*input));
i_zero(input);
input->info.service = "doveadm";
input->info.debug = doveadm_settings->auth_debug;
}
Expand Down Expand Up @@ -362,7 +362,7 @@ cmd_auth_master_input(const char *auth_master_socket_path,
struct master_auth_request master_auth_req;
buffer_t buf;

memset(&master_auth_req, 0, sizeof(master_auth_req));
i_zero(&master_auth_req);
master_auth_req.tag = 1;
master_auth_req.auth_pid = input->auth_pid;
master_auth_req.auth_id = input->auth_id;
Expand Down Expand Up @@ -549,7 +549,7 @@ cmd_user_mail_input(struct mail_storage_service_ctx *storage_service,
pool_t pool;
int ret;

memset(&service_input, 0, sizeof(service_input));
i_zero(&service_input);
service_input.module = "mail";
service_input.service = input->info.service;
service_input.username = input->username;
Expand Down
2 changes: 1 addition & 1 deletion src/doveadm/doveadm-cmd.c
Expand Up @@ -381,7 +381,7 @@ doveadm_build_options(const struct doveadm_cmd_param par[],
for(size_t i=0; par[i].name != NULL; i++) {
struct option longopt;

memset(&longopt, 0, sizeof(longopt));
i_zero(&longopt);
longopt.name = par[i].name;
if (par[i].short_opt != '\0') {
longopt.val = par[i].short_opt;
Expand Down
4 changes: 2 additions & 2 deletions src/doveadm/doveadm-dsync.c
Expand Up @@ -564,7 +564,7 @@ cmd_dsync_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user)
bool remote_only_changes;
int ret = 0;

memset(&set, 0, sizeof(set));
i_zero(&set);
if (_ctx->cur_client_ip.family != 0) {
/* include the doveadm client's IP address in the ps output */
set.process_title_prefix = t_strdup_printf(
Expand Down Expand Up @@ -772,7 +772,7 @@ static int dsync_init_ssl_ctx(struct dsync_cmd_context *ctx,
if (ctx->ssl_ctx != NULL)
return 0;

memset(&ssl_set, 0, sizeof(ssl_set));
i_zero(&ssl_set);
ssl_set.ca_dir = mail_set->ssl_client_ca_dir;
ssl_set.ca_file = mail_set->ssl_client_ca_file;
ssl_set.verify_remote_cert = TRUE;
Expand Down
8 changes: 4 additions & 4 deletions src/doveadm/doveadm-fs.c
Expand Up @@ -35,12 +35,12 @@ cmd_fs_init(int *argc, char **argv[], int own_arg_count, doveadm_command_t *cmd)
fs_cmd_help(cmd);
}

memset(&ssl_set, 0, sizeof(ssl_set));
i_zero(&ssl_set);
ssl_set.ca_dir = doveadm_settings->ssl_client_ca_dir;
ssl_set.ca_file = doveadm_settings->ssl_client_ca_file;
ssl_set.verbose = doveadm_debug;

memset(&fs_set, 0, sizeof(fs_set));
i_zero(&fs_set);
fs_set.ssl_client_set = &ssl_set;
fs_set.temp_dir = "/tmp";
fs_set.base_dir = doveadm_settings->base_dir;
Expand Down Expand Up @@ -343,7 +343,7 @@ cmd_fs_delete_dir_recursive(struct fs *fs, unsigned int async_count,
const char *fname, *const *fnamep;
int ret;

memset(&ctx, 0, sizeof(ctx));
i_zero(&ctx);
ctx.fs = fs;
ctx.path_prefix = path_prefix;
ctx.files_count = I_MAX(async_count, 1);
Expand Down Expand Up @@ -443,7 +443,7 @@ static void cmd_fs_delete_paths(int argc, char *argv[],

fs = cmd_fs_init(&argc, &argv, 0, cmd_fs_delete);

memset(&ctx, 0, sizeof(ctx));
i_zero(&ctx);
ctx.fs = fs;
ctx.path_prefix = "";
ctx.files_count = I_MAX(async_count, 1);
Expand Down
4 changes: 2 additions & 2 deletions src/doveadm/doveadm-kick.c
Expand Up @@ -41,7 +41,7 @@ kick_aggregate_line(struct who_context *_ctx, const struct who_line *line)
struct kick_pid *k_pid;
struct kick_user new_user, *user;

memset(&new_user, 0, sizeof(new_user));
i_zero(&new_user);

k_pid = hash_table_lookup(ctx->pids, POINTER_CAST(line->pid));
if (k_pid == NULL) {
Expand Down Expand Up @@ -179,7 +179,7 @@ static void cmd_kick(struct doveadm_cmd_context *cctx)
const char *const *masks;
struct kick_context ctx;

memset(&ctx, 0, sizeof(ctx));
i_zero(&ctx);
if (!doveadm_cmd_param_str(cctx, "socket-path", &(ctx.who.anvil_path)))
ctx.who.anvil_path = t_strconcat(doveadm_settings->base_dir, "/anvil", NULL);
(void)doveadm_cmd_param_bool(cctx, "force", &(ctx.force_kick));
Expand Down
4 changes: 2 additions & 2 deletions src/doveadm/doveadm-log.c
Expand Up @@ -35,7 +35,7 @@ cmd_log_test(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED)
master_service->flags |= MASTER_SERVICE_FLAG_DONT_LOG_TO_STDERR;
master_service_init_log(master_service, "doveadm: ");

memset(&ctx, 0, sizeof(ctx));
i_zero(&ctx);
for (i = 0; i < LAST_LOG_TYPE; i++) {
const char *prefix = failure_log_type_prefixes[i];

Expand Down Expand Up @@ -221,7 +221,7 @@ static void cmd_log_find(int argc, char *argv[])
struct log_find_context ctx;
unsigned int i;

memset(&ctx, 0, sizeof(ctx));
i_zero(&ctx);
ctx.pool = pool_alloconly_create("log file", 1024*32);
hash_table_create(&ctx.files, ctx.pool, 0, str_hash, strcmp);

Expand Down
2 changes: 1 addition & 1 deletion src/doveadm/doveadm-mail-batch.c
Expand Up @@ -65,7 +65,7 @@ cmd_batch_add(struct batch_cmd_context *batchctx,
if (cmd_ver2 == NULL)
cmd = doveadm_mail_cmd_find_from_argv(argv[0], &argc, &argv);
else {
memset(&tmpcmd, 0, sizeof(tmpcmd));
i_zero(&tmpcmd);
tmpcmd.usage_args = cmd_ver2->usage;
tmpcmd.name = cmd_ver2->name;
tmpcmd.alloc = cmd_ver2->mail_cmd;
Expand Down
4 changes: 2 additions & 2 deletions src/doveadm/doveadm-mail-fetch.c
Expand Up @@ -533,10 +533,10 @@ static void parse_fetch_fields(struct fetch_cmd_context *ctx, const char *str)
struct fetch_field hdr_field, body_field;
struct imap_msgpart *msgpart;

memset(&hdr_field, 0, sizeof(hdr_field));
i_zero(&hdr_field);
hdr_field.print = fetch_hdr_field;

memset(&body_field, 0, sizeof(body_field));
i_zero(&body_field);
body_field.print = fetch_body_field;

t_array_init(&ctx->fields, 32);
Expand Down

0 comments on commit 74d223d

Please sign in to comment.