Commit 8b5715db 8b5715db380634336a231b0c8573c350992c8dce by Sergey Poznyakoff

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.
1 parent 75b1c55e
......@@ -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);
......
......@@ -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;
......
......@@ -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)
......
......@@ -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");
}
......
......@@ -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)
......
......@@ -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);
......
......@@ -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++;
......