* [PATCH 1/2] cli/config: allocate config using talloc_zero
@ 2016-12-17 16:20 Jani Nikula
2016-12-17 16:20 ` [PATCH 2/2] cli/config: rename name to key in _config_set_list Jani Nikula
2017-01-07 12:33 ` [PATCH 1/2] cli/config: allocate config using talloc_zero David Bremner
0 siblings, 2 replies; 3+ messages in thread
From: Jani Nikula @ 2016-12-17 16:20 UTC (permalink / raw)
To: notmuch
Do not initialize each field separately. It's more robust to allocate
the config with zero initialization, and only set the non-zero
defaults individually.
---
notmuch-config.c | 20 ++++----------------
1 file changed, 4 insertions(+), 16 deletions(-)
diff --git a/notmuch-config.c b/notmuch-config.c
index cdb4088d1535..6d50be4c3150 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -334,7 +334,7 @@ notmuch_config_open (void *ctx,
int file_had_search_group;
int file_had_crypto_group;
- notmuch_config_t *config = talloc (ctx, notmuch_config_t);
+ notmuch_config_t *config = talloc_zero (ctx, notmuch_config_t);
if (config == NULL) {
fprintf (stderr, "Out of memory.\n");
return NULL;
@@ -342,6 +342,9 @@ notmuch_config_open (void *ctx,
talloc_set_destructor (config, notmuch_config_destructor);
+ /* non-zero defaults */
+ config->maildir_synchronize_flags = TRUE;
+
if (filename) {
config->filename = talloc_strdup (config, filename);
} else if ((notmuch_config_env = getenv ("NOTMUCH_CONFIG"))) {
@@ -353,21 +356,6 @@ notmuch_config_open (void *ctx,
config->key_file = g_key_file_new ();
- config->is_new = FALSE;
- config->database_path = NULL;
- config->user_name = NULL;
- config->user_primary_email = NULL;
- config->user_other_email = NULL;
- config->user_other_email_length = 0;
- config->new_tags = NULL;
- config->new_tags_length = 0;
- config->new_ignore = NULL;
- config->new_ignore_length = 0;
- config->maildir_synchronize_flags = TRUE;
- config->search_exclude_tags = NULL;
- config->search_exclude_tags_length = 0;
- config->crypto_gpg_path = NULL;
-
if (! get_config_from_file (config, create_new)) {
talloc_free (config);
return NULL;
--
2.10.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] cli/config: rename name to key in _config_set_list
2016-12-17 16:20 [PATCH 1/2] cli/config: allocate config using talloc_zero Jani Nikula
@ 2016-12-17 16:20 ` Jani Nikula
2017-01-07 12:33 ` [PATCH 1/2] cli/config: allocate config using talloc_zero David Bremner
1 sibling, 0 replies; 3+ messages in thread
From: Jani Nikula @ 2016-12-17 16:20 UTC (permalink / raw)
To: notmuch
The other getters and setters speak of key, follow suit. No functional
changes.
---
notmuch-config.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/notmuch-config.c b/notmuch-config.c
index 6d50be4c3150..b202bb1e2299 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -631,11 +631,11 @@ _config_get_list (notmuch_config_t *config,
static void
_config_set_list (notmuch_config_t *config,
- const char *group, const char *name,
+ const char *group, const char *key,
const char *list[],
size_t length, const char ***config_var )
{
- g_key_file_set_string_list (config->key_file, group, name, list, length);
+ g_key_file_set_string_list (config->key_file, group, key, list, length);
/* drop the cached value */
talloc_free (*config_var);
--
2.10.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] cli/config: allocate config using talloc_zero
2016-12-17 16:20 [PATCH 1/2] cli/config: allocate config using talloc_zero Jani Nikula
2016-12-17 16:20 ` [PATCH 2/2] cli/config: rename name to key in _config_set_list Jani Nikula
@ 2017-01-07 12:33 ` David Bremner
1 sibling, 0 replies; 3+ messages in thread
From: David Bremner @ 2017-01-07 12:33 UTC (permalink / raw)
To: Jani Nikula, notmuch
Jani Nikula <jani@nikula.org> writes:
> Do not initialize each field separately. It's more robust to allocate
> the config with zero initialization, and only set the non-zero
> defaults individually.
Series pushed to master.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-01-07 12:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-17 16:20 [PATCH 1/2] cli/config: allocate config using talloc_zero Jani Nikula
2016-12-17 16:20 ` [PATCH 2/2] cli/config: rename name to key in _config_set_list Jani Nikula
2017-01-07 12:33 ` [PATCH 1/2] cli/config: allocate config using talloc_zero David Bremner
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).