build: fix some scan-build warnings

This commit is contained in:
Dirk-Jan C. Binnema 2022-02-07 17:36:34 +02:00
parent 8493e8649d
commit e818e94d0e
6 changed files with 132 additions and 152 deletions

View File

@ -149,14 +149,14 @@ SCM_DEFINE_PUBLIC(mu_initialize,
muhome = scm_to_utf8_string(MUHOME); muhome = scm_to_utf8_string(MUHOME);
rv = mu_guile_init_instance(muhome); rv = mu_guile_init_instance(muhome);
free(muhome); if (!rv) {
free(muhome);
if (!rv) mu_guile_error(FUNC_NAME, 0, "Failed to initialize mu", SCM_UNSPECIFIED);
return mu_guile_error(FUNC_NAME, 0, "Failed to initialize mu", SCM_UNSPECIFIED); }
g_debug("mu-guile: initialized @ %s (%p)", g_debug("mu-guile: initialized @ %s (%p)",
muhome ? muhome : "<default>", muhome ? muhome : "<default>", StoreSingleton.get());
StoreSingleton.get()); free(muhome);
/* cleanup when we're exiting */ /* cleanup when we're exiting */
atexit(mu_guile_uninit_instance); atexit(mu_guile_uninit_instance);

View File

@ -282,20 +282,15 @@ get_str_field(MuMsg* self, MuMsgFieldId mfid)
static gint64 static gint64
get_num_field(MuMsg* self, MuMsgFieldId mfid) get_num_field(MuMsg* self, MuMsgFieldId mfid)
{ {
guint64 val;
val = -1;
if (self->_doc && mu_msg_field_xapian_value(mfid)) if (self->_doc && mu_msg_field_xapian_value(mfid))
val = mu_msg_doc_get_num_field(self->_doc, mfid); return mu_msg_doc_get_num_field(self->_doc, mfid);
else {
/* if we don't have a file object yet, we need to
* create it from the file on disk */
if (!mu_msg_load_msg_file(self, NULL))
return -1;
val = mu_msg_file_get_num_field(self->_file, mfid);
}
return val; /* if we don't have a file object yet, we need to
* create it from the file on disk */
if (!mu_msg_load_msg_file(self, NULL))
return -1;
return mu_msg_file_get_num_field(self->_file, mfid);
} }
const char* const char*

View File

@ -306,10 +306,6 @@ mu_script_guile_run(MuScriptInfo* msi, const char* muhome, const char** args, GE
g_return_val_if_fail(msi, FALSE); g_return_val_if_fail(msi, FALSE);
g_return_val_if_fail(muhome, FALSE); g_return_val_if_fail(muhome, FALSE);
argv = g_new0(char*, 6);
argv[0] = g_strdup(GUILE_BINARY);
argv[1] = g_strdup("-l");
if (access(mu_script_info_path(msi), R_OK) != 0) { if (access(mu_script_info_path(msi), R_OK) != 0) {
mu_util_g_set_error(err, mu_util_g_set_error(err,
MU_ERROR_FILE_CANNOT_READ, MU_ERROR_FILE_CANNOT_READ,
@ -318,13 +314,17 @@ mu_script_guile_run(MuScriptInfo* msi, const char* muhome, const char** args, GE
return FALSE; return FALSE;
} }
argv = g_new0(char*, 6);
argv[0] = g_strdup(GUILE_BINARY);
argv[1] = g_strdup("-l");
s = mu_script_info_path(msi); s = mu_script_info_path(msi);
argv[2] = g_strdup(s ? s : ""); argv[2] = g_strdup(s ? s : "");
mainargs = mu_str_quoted_from_strv(args); mainargs = mu_str_quoted_from_strv(args);
expr = g_strdup_printf("(main '(\"%s\" \"--muhome=%s\" %s))", expr = g_strdup_printf("(main '(\"%s\" \"--muhome=%s\" %s))",
mu_script_info_name(msi), mu_script_info_name(msi),
muhome, muhome,
mainargs ? mainargs : ""); mainargs ? mainargs : "");
g_free(mainargs); g_free(mainargs);

View File

@ -283,7 +283,6 @@ test_mu_msg_references(void)
g_assert_cmpstr((char*)refs->data, ==, "non-exist-03@msg.id"); g_assert_cmpstr((char*)refs->data, ==, "non-exist-03@msg.id");
refs = g_slist_next(refs); refs = g_slist_next(refs);
g_assert_cmpstr((char*)refs->data, ==, "non-exist-04@msg.id"); g_assert_cmpstr((char*)refs->data, ==, "non-exist-04@msg.id");
refs = g_slist_next(refs);
mu_msg_unref(msg); mu_msg_unref(msg);
} }
@ -313,7 +312,6 @@ test_mu_msg_references_dups(void)
g_assert_cmpstr((char*)refs->data, ==, "439A1E03.3090604@euler.org"); g_assert_cmpstr((char*)refs->data, ==, "439A1E03.3090604@euler.org");
refs = g_slist_next(refs); refs = g_slist_next(refs);
g_assert_cmpstr((char*)refs->data, ==, "20051211184308.GB13513@gauss.org"); g_assert_cmpstr((char*)refs->data, ==, "20051211184308.GB13513@gauss.org");
refs = g_slist_next(refs);
mlist = mu_msg_get_mailing_list(msg); mlist = mu_msg_get_mailing_list(msg);
g_assert_cmpstr(mlist, ==, "Example of List Id"); g_assert_cmpstr(mlist, ==, "Example of List Id");

View File

@ -31,216 +31,205 @@
#include "mu-util.h" #include "mu-util.h"
static void static void
test_mu_util_dir_expand_00 (void) test_mu_util_dir_expand_00(void)
{ {
#ifdef HAVE_WORDEXP_H #ifdef HAVE_WORDEXP_H
gchar *got, *expected; gchar *got, *expected;
got = mu_util_dir_expand ("~/IProbablyDoNotExist"); got = mu_util_dir_expand("~/IProbablyDoNotExist");
expected = g_strdup_printf ("%s%cIProbablyDoNotExist", expected = g_strdup_printf("%s%cIProbablyDoNotExist",
getenv("HOME"), G_DIR_SEPARATOR); getenv("HOME"), G_DIR_SEPARATOR);
g_assert_cmpstr (got,==,expected); g_assert_cmpstr(got, ==, expected);
g_free (got); g_free(got);
g_free (expected); g_free(expected);
#endif /*HAVE_WORDEXP_H*/ #endif /*HAVE_WORDEXP_H*/
} }
static void static void
test_mu_util_dir_expand_01 (void) test_mu_util_dir_expand_01(void)
{ {
/* XXXX: the testcase does not work when using some dir /* XXXX: the testcase does not work when using some dir
* setups; (see issue #585), although the code should still * setups; (see issue #585), although the code should still
* work. Turn of the test for now */ * work. Turn of the test for now */
return; return;
#ifdef HAVE_WORDEXP_H #ifdef HAVE_WORDEXP_H
{ {
gchar *got, *expected; gchar *got, *expected;
got = mu_util_dir_expand ("~/Desktop"); got = mu_util_dir_expand("~/Desktop");
expected = g_strdup_printf ("%s%cDesktop", expected = g_strdup_printf("%s%cDesktop",
getenv("HOME"), G_DIR_SEPARATOR); getenv("HOME"), G_DIR_SEPARATOR);
g_assert_cmpstr (got,==,expected); g_assert_cmpstr(got, ==, expected);
g_free (got); g_free(got);
g_free (expected); g_free(expected);
} }
#endif /*HAVE_WORDEXP_H*/ #endif /*HAVE_WORDEXP_H*/
} }
static void static void
test_mu_util_guess_maildir_01 (void) test_mu_util_guess_maildir_01(void)
{ {
char *got; char* got;
const char *expected; const char* expected;
/* skip the test if there's no /tmp */ /* skip the test if there's no /tmp */
if (access ("/tmp", F_OK)) if (access("/tmp", F_OK))
return; return;
g_setenv ("MAILDIR", "/tmp", TRUE); g_setenv("MAILDIR", "/tmp", TRUE);
got = mu_util_guess_maildir (); got = mu_util_guess_maildir();
expected = "/tmp"; expected = "/tmp";
g_assert_cmpstr (got,==,expected); g_assert_cmpstr(got, ==, expected);
g_free (got); g_free(got);
} }
static void static void
test_mu_util_guess_maildir_02 (void) test_mu_util_guess_maildir_02(void)
{ {
char *got, *mdir; char *got, *mdir;
g_unsetenv ("MAILDIR"); g_unsetenv("MAILDIR");
mdir = g_strdup_printf ("%s%cMaildir", mdir = g_strdup_printf("%s%cMaildir",
getenv("HOME"), G_DIR_SEPARATOR); getenv("HOME"), G_DIR_SEPARATOR);
got = mu_util_guess_maildir (); got = mu_util_guess_maildir();
if (access (mdir, F_OK) == 0) if (access(mdir, F_OK) == 0)
g_assert_cmpstr (got, ==, mdir); g_assert_cmpstr(got, ==, mdir);
else else
g_assert_cmpstr (got, == , NULL); g_assert_cmpstr(got, ==, NULL);
g_free (got); g_free(got);
g_free (mdir); g_free(mdir);
} }
static void static void
test_mu_util_check_dir_01 (void) test_mu_util_check_dir_01(void)
{ {
if (g_access ("/usr/bin", F_OK) == 0) { if (g_access("/usr/bin", F_OK) == 0) {
g_assert_cmpuint ( g_assert_cmpuint(
mu_util_check_dir ("/usr/bin", TRUE, FALSE) == TRUE, mu_util_check_dir("/usr/bin", TRUE, FALSE) == TRUE,
==, ==,
g_access ("/usr/bin", R_OK) == 0); g_access("/usr/bin", R_OK) == 0);
} }
} }
static void static void
test_mu_util_check_dir_02 (void) test_mu_util_check_dir_02(void)
{ {
if (g_access ("/tmp", F_OK) == 0) { if (g_access("/tmp", F_OK) == 0) {
g_assert_cmpuint ( g_assert_cmpuint(
mu_util_check_dir ("/tmp", FALSE, TRUE) == TRUE, mu_util_check_dir("/tmp", FALSE, TRUE) == TRUE,
==, ==,
g_access ("/tmp", W_OK) == 0); g_access("/tmp", W_OK) == 0);
} }
} }
static void static void
test_mu_util_check_dir_03 (void) test_mu_util_check_dir_03(void)
{ {
if (g_access (".", F_OK) == 0) { if (g_access(".", F_OK) == 0) {
g_assert_cmpuint ( g_assert_cmpuint(
mu_util_check_dir (".", TRUE, TRUE) == TRUE, mu_util_check_dir(".", TRUE, TRUE) == TRUE,
==, ==,
g_access (".", W_OK | R_OK) == 0); g_access(".", W_OK | R_OK) == 0);
} }
} }
static void static void
test_mu_util_check_dir_04 (void) test_mu_util_check_dir_04(void)
{ {
/* not a dir, so it must be false */ /* not a dir, so it must be false */
g_assert_cmpuint ( g_assert_cmpuint(
mu_util_check_dir ("test-util.c", TRUE, TRUE), mu_util_check_dir("test-util.c", TRUE, TRUE),
==, ==,
FALSE); FALSE);
} }
static void static void
test_mu_util_get_dtype_with_lstat (void) test_mu_util_get_dtype_with_lstat(void)
{ {
g_assert_cmpuint ( g_assert_cmpuint(
mu_util_get_dtype (MU_TESTMAILDIR, TRUE), ==, DT_DIR); mu_util_get_dtype(MU_TESTMAILDIR, TRUE), ==, DT_DIR);
g_assert_cmpuint ( g_assert_cmpuint(
mu_util_get_dtype (MU_TESTMAILDIR2, TRUE), ==, DT_DIR); mu_util_get_dtype(MU_TESTMAILDIR2, TRUE), ==, DT_DIR);
g_assert_cmpuint ( g_assert_cmpuint(
mu_util_get_dtype (MU_TESTMAILDIR2 "/Foo/cur/mail5", TRUE), mu_util_get_dtype(MU_TESTMAILDIR2 "/Foo/cur/mail5", TRUE),
==, DT_REG); ==, DT_REG);
} }
static void static void
test_mu_util_supports (void) test_mu_util_supports(void)
{ {
gboolean has_guile; gboolean has_guile;
gchar *path; gchar* path;
has_guile = FALSE;
#ifdef BUILD_GUILE #ifdef BUILD_GUILE
has_guile = TRUE; has_guile = TRUE;
#else
has_guile = FALSE;
#endif /*BUILD_GUILE*/ #endif /*BUILD_GUILE*/
g_assert_cmpuint (mu_util_supports (MU_FEATURE_GUILE), == ,has_guile); g_assert_cmpuint(mu_util_supports(MU_FEATURE_GUILE), ==, has_guile);
path = g_find_program_in_path ("gnuplot"); path = g_find_program_in_path("gnuplot");
g_free (path); g_free(path);
g_assert_cmpuint (mu_util_supports (MU_FEATURE_GNUPLOT),==, g_assert_cmpuint(mu_util_supports(MU_FEATURE_GNUPLOT), ==,
path ? TRUE : FALSE); path ? TRUE : FALSE);
g_assert_cmpuint ( g_assert_cmpuint(
mu_util_supports (MU_FEATURE_GNUPLOT|MU_FEATURE_GUILE), mu_util_supports(MU_FEATURE_GNUPLOT | MU_FEATURE_GUILE),
==, ==,
has_guile && path ? TRUE : FALSE); has_guile && path ? TRUE : FALSE);
} }
static void static void
test_mu_util_program_in_path (void) test_mu_util_program_in_path(void)
{ {
g_assert_cmpuint (mu_util_program_in_path("ls"),==,TRUE); g_assert_cmpuint(mu_util_program_in_path("ls"), ==, TRUE);
} }
int int
main (int argc, char *argv[]) main(int argc, char* argv[])
{ {
g_test_init (&argc, &argv, NULL); g_test_init(&argc, &argv, NULL);
/* mu_util_dir_expand */ /* mu_util_dir_expand */
g_test_add_func ("/mu-util/mu-util-dir-expand-00", g_test_add_func("/mu-util/mu-util-dir-expand-00",
test_mu_util_dir_expand_00); test_mu_util_dir_expand_00);
g_test_add_func ("/mu-util/mu-util-dir-expand-01", g_test_add_func("/mu-util/mu-util-dir-expand-01",
test_mu_util_dir_expand_01); test_mu_util_dir_expand_01);
/* mu_util_guess_maildir */ /* mu_util_guess_maildir */
g_test_add_func ("/mu-util/mu-util-guess-maildir-01", g_test_add_func("/mu-util/mu-util-guess-maildir-01",
test_mu_util_guess_maildir_01); test_mu_util_guess_maildir_01);
g_test_add_func ("/mu-util/mu-util-guess-maildir-02", g_test_add_func("/mu-util/mu-util-guess-maildir-02",
test_mu_util_guess_maildir_02); test_mu_util_guess_maildir_02);
/* mu_util_check_dir */ /* mu_util_check_dir */
g_test_add_func ("/mu-util/mu-util-check-dir-01", g_test_add_func("/mu-util/mu-util-check-dir-01",
test_mu_util_check_dir_01); test_mu_util_check_dir_01);
g_test_add_func ("/mu-util/mu-util-check-dir-02", g_test_add_func("/mu-util/mu-util-check-dir-02",
test_mu_util_check_dir_02); test_mu_util_check_dir_02);
g_test_add_func ("/mu-util/mu-util-check-dir-03", g_test_add_func("/mu-util/mu-util-check-dir-03",
test_mu_util_check_dir_03); test_mu_util_check_dir_03);
g_test_add_func ("/mu-util/mu-util-check-dir-04", g_test_add_func("/mu-util/mu-util-check-dir-04",
test_mu_util_check_dir_04); test_mu_util_check_dir_04);
g_test_add_func ("/mu-util/mu-util-get-dtype-with-lstat", g_test_add_func("/mu-util/mu-util-get-dtype-with-lstat",
test_mu_util_get_dtype_with_lstat); test_mu_util_get_dtype_with_lstat);
g_test_add_func ("/mu-util/mu-util-supports", test_mu_util_supports); g_test_add_func("/mu-util/mu-util-supports", test_mu_util_supports);
g_test_add_func ("/mu-util/mu-util-program-in-path", g_test_add_func("/mu-util/mu-util-program-in-path",
test_mu_util_program_in_path); test_mu_util_program_in_path);
return g_test_run (); return g_test_run();
} }

View File

@ -62,14 +62,14 @@ get_output_format(const char* formatstr)
return MU_CONFIG_FORMAT_UNKNOWN; return MU_CONFIG_FORMAT_UNKNOWN;
} }
#define expand_dir(D) \ #define expand_dir(D) \
if ((D)) { \ if ((D)) { \
char* exp; \ char* exp; \
exp = mu_util_dir_expand((D)); \ exp = mu_util_dir_expand((D)); \
if (exp) { \ if (exp) { \
g_free((D)); \ g_free((D)); \
(D) = exp; \ (D) = exp; \
} \ } \
} }
static void static void
@ -612,7 +612,7 @@ config_options_group_extract()
"try to 'play' (open) the extracted parts", "try to 'play' (open) the extracted parts",
NULL}, NULL},
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}}; {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
og = g_option_group_new("extract", "Options for the 'extract' command", "", NULL, NULL); og = g_option_group_new("extract", "Options for the 'extract' command", "", NULL, NULL);
g_option_group_add_entries(og, entries); g_option_group_add_entries(og, entries);
g_option_group_add_entries(og, crypto_option_entries()); g_option_group_add_entries(og, crypto_option_entries());
@ -758,7 +758,7 @@ massage_help(const char* help)
GRegex* rx; GRegex* rx;
char* str; char* str;
rx = g_regex_new("^Usage:.*\n.*\n", (GRegexCompileFlags)0, G_REGEX_MATCH_NEWLINE_ANY, NULL); rx = g_regex_new("^Usage:.*\n.*\n", (GRegexCompileFlags)0, G_REGEX_MATCH_NEWLINE_ANY, NULL);
str = g_regex_replace(rx, help, -1, 0, "", G_REGEX_MATCH_NEWLINE_ANY, NULL); str = g_regex_replace(rx, help, -1, 0, "", G_REGEX_MATCH_NEWLINE_ANY, NULL);
g_regex_unref(rx); g_regex_unref(rx);
return str; return str;
@ -841,8 +841,6 @@ parse_params(int* argcp, char*** argvp, GError** err)
context = g_option_context_new("- mu general options"); context = g_option_context_new("- mu general options");
g_option_context_set_help_enabled(context, TRUE); g_option_context_set_help_enabled(context, TRUE);
rv = TRUE;
g_option_context_set_main_group(context, config_options_group_mu()); g_option_context_set_main_group(context, config_options_group_mu());
g_option_context_set_ignore_unknown_options(context, FALSE); g_option_context_set_ignore_unknown_options(context, FALSE);