summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2017-06-15 17:04:08 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2017-06-15 17:04:08 (GMT)
commit8b5715db380634336a231b0c8573c350992c8dce (patch) (side-by-side diff)
treebdbd33372ceda331f70f7248dd85d63bff0ed40b
parent75b1c55e4db1c0b90e898b1375f1489e72719127 (diff)
downloadmailutils-8b5715db380634336a231b0c8573c350992c8dce.tar.gz
mailutils-8b5715db380634336a231b0c8573c350992c8dce.tar.bz2
Make sure all loci are properly initialized before first use.
Clean up semantics of initializers. Each locus type can be initialized either statically (by assigning the MU_LOCUS_*_INITIALIZER macro), or dynamically (by calling mu_locus_*_init function). Whatever method is used, it is important that it be initialized prior to using any other mu_locus_* function. * include/mailutils/locus.h (mu_locus_point_init): Takes single argument. Returns nothing. (mu_locus_range_init): New proto. * libmailutils/locus/locus.c (mu_locus_point_init): Rewrite. (mu_locus_range_init): New function. * libmailutils/cfg/parser.y (mu_cfg_alloc_node): Initialize locus. * libmailutils/tests/logstr.c: Fix printf argyment types. * libmu_sieve/extensions/moderator.c (moderator_filter_message): Initialize locus. * libmu_sieve/sieve-gram.y (node_alloc): Likewise. * mu/libexec/logger.c (parse_locus_point, set_locus): Likewise.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/mailutils/locus.h3
-rw-r--r--libmailutils/cfg/parser.y1
-rw-r--r--libmailutils/locus/locus.c18
-rw-r--r--libmailutils/tests/logstr.c20
-rw-r--r--libmu_sieve/extensions/moderator.c2
-rw-r--r--libmu_sieve/sieve-gram.y5
-rw-r--r--mu/libexec/logger.c6
7 files changed, 29 insertions, 26 deletions
diff --git a/include/mailutils/locus.h b/include/mailutils/locus.h
index 1f94c69..f8efa13 100644
--- a/include/mailutils/locus.h
+++ b/include/mailutils/locus.h
@@ -54,11 +54,12 @@ int mu_ident_deref (char const *);
void mu_ident_stat (mu_stream_t str);
int mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename);
-int mu_locus_point_init (struct mu_locus_point *pt, const char *filename);
+void mu_locus_point_init (struct mu_locus_point *pt);
void mu_locus_point_deinit (struct mu_locus_point *pt);
int mu_locus_point_copy (struct mu_locus_point *dest,
struct mu_locus_point const *src);
+void mu_locus_range_init (struct mu_locus_range *dest);
int mu_locus_range_copy (struct mu_locus_range *dest,
struct mu_locus_range const *src);
void mu_locus_range_deinit (struct mu_locus_range *lr);
diff --git a/libmailutils/cfg/parser.y b/libmailutils/cfg/parser.y
index e4654bc..4503c77 100644
--- a/libmailutils/cfg/parser.y
+++ b/libmailutils/cfg/parser.y
@@ -94,6 +94,7 @@ mu_cfg_alloc_node (enum mu_cfg_node_type type, struct mu_locus_range *loc,
size_t size = sizeof *np + strlen (tag) + 1;
np = mu_alloc (size);
np->type = type;
+ mu_locus_range_init (&np->locus);
mu_locus_range_copy (&np->locus, loc);
p = (char*) (np + 1);
np->tag = p;
diff --git a/libmailutils/locus/locus.c b/libmailutils/locus/locus.c
index 49648fd..cfa8080 100644
--- a/libmailutils/locus/locus.c
+++ b/libmailutils/locus/locus.c
@@ -36,16 +36,10 @@ mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename)
return 0;
}
-int
-mu_locus_point_init (struct mu_locus_point *pt, const char *filename)
+void
+mu_locus_point_init (struct mu_locus_point *pt)
{
- int rc = mu_locus_point_set_file (pt, filename);
- if (rc == 0)
- {
- pt->mu_line = 0;
- pt->mu_col = 0;
- }
- return rc;
+ memset (pt, 0, sizeof *pt);
}
void
@@ -68,6 +62,12 @@ mu_locus_point_copy (struct mu_locus_point *dest,
return rc;
}
+void
+mu_locus_range_init (struct mu_locus_range *dest)
+{
+ memset (dest, 0, sizeof *dest);
+}
+
int
mu_locus_range_copy (struct mu_locus_range *dest,
struct mu_locus_range const *src)
diff --git a/libmailutils/tests/logstr.c b/libmailutils/tests/logstr.c
index 269a613..bf65e21 100644
--- a/libmailutils/tests/logstr.c
+++ b/libmailutils/tests/logstr.c
@@ -498,7 +498,7 @@ fmt_locus1 (mu_stream_t str)
{
char *file = "a";
mu_stream_printf (str, "\033f<%d>%s\033l<%d>one\n",
- strlen (file), file, 10);
+ (int) strlen (file), file, 10);
}
/* Check ESC-f, ESC-l, and ESC-c format specifiers.
@@ -510,7 +510,7 @@ fmt_locus2 (mu_stream_t str)
{
char *file = "a";
mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>one\n",
- strlen (file), file, 10, 5);
+ (int) strlen (file), file, 10, 5);
}
/* Check setting range with ESC-f, ESC-l, and ESC-c format specifiers.
@@ -523,8 +523,8 @@ fmt_locus3 (mu_stream_t str)
char *file[] = { "a", "b" };
mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>"
"\033f<%d>%s\033l<%d>\033c<%d>one\n",
- strlen (file[0]), file[0], 10, 5,
- strlen (file[1]), file[1], 14, 8);
+ (int) strlen (file[0]), file[0], 10, 5,
+ (int) strlen (file[1]), file[1], 14, 8);
}
/* Check that ESC-f, ESC-l, and ESC-c format specifiers don't clobber
@@ -552,8 +552,8 @@ fmt_locus4 (mu_stream_t str)
mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>"
"\033f<%d>%s\033l<%d>\033c<%d>one\n",
- strlen (file[0]), file[0], 10, 5,
- strlen (file[1]), file[1], 14, 8);
+ (int) strlen (file[0]), file[0], 10, 5,
+ (int) strlen (file[1]), file[1], 14, 8);
mu_stream_printf (str, "default\n");
}
@@ -586,8 +586,8 @@ fmt_locus5 (mu_stream_t str)
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>"
"\033f<%d>%s\033l<%d>\033c<%d>one\n",
- strlen (file[0]), file[0], 10, 5,
- strlen (file[1]), file[1], 14, 8);
+ (int) strlen (file[0]), file[0], 10, 5,
+ (int) strlen (file[1]), file[1], 14, 8);
mu_stream_printf (str, "default\n");
}
@@ -619,8 +619,8 @@ fmt_locus6 (mu_stream_t str)
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mu_stream_printf (str, "\033S\033f<%d>%s\033l<%d>\033c<%d>"
"\033f<%d>%s\033l<%d>\033c<%d>one\n",
- strlen (file[0]), file[0], 10, 5,
- strlen (file[1]), file[1], 14, 8);
+ (int) strlen (file[0]), file[0], 10, 5,
+ (int) strlen (file[1]), file[1], 14, 8);
mu_stream_printf (str, "default\n");
}
diff --git a/libmu_sieve/extensions/moderator.c b/libmu_sieve/extensions/moderator.c
index 510c00f..f82e615 100644
--- a/libmu_sieve/extensions/moderator.c
+++ b/libmu_sieve/extensions/moderator.c
@@ -103,7 +103,7 @@ moderator_filter_message (mu_sieve_machine_t mach,
}
else if (mu_sieve_get_tag (mach, "program", SVT_STRING, &arg))
{
- struct mu_locus_range locrange;
+ struct mu_locus_range locrange = MU_LOCUS_RANGE_INITIALIZER;
rc = mu_sieve_machine_clone (mach, &newmach);
if (rc)
diff --git a/libmu_sieve/sieve-gram.y b/libmu_sieve/sieve-gram.y
index 077011e..38a85b2 100644
--- a/libmu_sieve/sieve-gram.y
+++ b/libmu_sieve/sieve-gram.y
@@ -388,6 +388,7 @@ node_alloc (enum mu_sieve_node_type type, struct mu_locus_range *lr)
{
node->prev = node->next = NULL;
node->type = type;
+ mu_locus_range_init (&node->locus);
mu_locus_range_copy (&node->locus, lr);
}
return node;
@@ -1585,8 +1586,8 @@ mu_sieve_compile_buffer (mu_sieve_machine_t mach,
const char *fname, int line)
{
int rc;
- struct mu_locus_point loc;
- mu_locus_point_init (&loc, fname);
+ struct mu_locus_point loc = MU_LOCUS_POINT_INITIALIZER;
+ mu_locus_point_set_file (&loc, fname);
loc.mu_line = line;
rc = mu_sieve_compile_text (mach, buf, bufsize, &loc);
mu_locus_point_deinit (&loc);
diff --git a/mu/libexec/logger.c b/mu/libexec/logger.c
index 80be6fc..daa85a9 100644
--- a/mu/libexec/logger.c
+++ b/mu/libexec/logger.c
@@ -26,7 +26,7 @@ static char logger_args_doc[] = N_("[TEXT]");
static char *input_file = NULL;
static int logger_type = MU_STRERR_STDERR;
static int log_severity = MU_LOG_ERROR;
-static struct mu_locus_range locus;
+static struct mu_locus_range locus = MU_LOCUS_RANGE_INITIALIZER;
static int syslog_facility = LOG_USER;
static int syslog_priority = LOG_ERR;
static char *syslog_tag = NULL;
@@ -95,7 +95,7 @@ parse_locus_point (char **ptr, struct mu_locus_point *pt,
char *end;
*s++ = 0;
if (*str)
- mu_locus_point_init (pt, str);
+ mu_locus_point_set_file (pt, str);
pt->mu_line = strtoul (s, &end, 10);
if (end == s)
{
@@ -135,7 +135,7 @@ set_locus (struct mu_parseopt *po, struct mu_option *opt,
parse_locus_point (&s, &locus.beg, po);
if (*s == '-')
{
- mu_locus_point_init (&locus.end, locus.beg.mu_file);
+ mu_locus_point_set_file (&locus.end, locus.beg.mu_file);
locus.end.mu_line = locus.beg.mu_line;
locus.end.mu_col = locus.end.mu_col;
s++;

Return to:

Send suggestions and report system problems to the System administrator.