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.
Showing
7 changed files
with
29 additions
and
26 deletions
... | @@ -54,11 +54,12 @@ int mu_ident_deref (char const *); | ... | @@ -54,11 +54,12 @@ int mu_ident_deref (char const *); |
54 | void mu_ident_stat (mu_stream_t str); | 54 | void mu_ident_stat (mu_stream_t str); |
55 | 55 | ||
56 | int mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename); | 56 | int mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename); |
57 | int mu_locus_point_init (struct mu_locus_point *pt, const char *filename); | 57 | void mu_locus_point_init (struct mu_locus_point *pt); |
58 | void mu_locus_point_deinit (struct mu_locus_point *pt); | 58 | void mu_locus_point_deinit (struct mu_locus_point *pt); |
59 | int mu_locus_point_copy (struct mu_locus_point *dest, | 59 | int mu_locus_point_copy (struct mu_locus_point *dest, |
60 | struct mu_locus_point const *src); | 60 | struct mu_locus_point const *src); |
61 | 61 | ||
62 | void mu_locus_range_init (struct mu_locus_range *dest); | ||
62 | int mu_locus_range_copy (struct mu_locus_range *dest, | 63 | int mu_locus_range_copy (struct mu_locus_range *dest, |
63 | struct mu_locus_range const *src); | 64 | struct mu_locus_range const *src); |
64 | void mu_locus_range_deinit (struct mu_locus_range *lr); | 65 | 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, | ... | @@ -94,6 +94,7 @@ mu_cfg_alloc_node (enum mu_cfg_node_type type, struct mu_locus_range *loc, |
94 | size_t size = sizeof *np + strlen (tag) + 1; | 94 | size_t size = sizeof *np + strlen (tag) + 1; |
95 | np = mu_alloc (size); | 95 | np = mu_alloc (size); |
96 | np->type = type; | 96 | np->type = type; |
97 | mu_locus_range_init (&np->locus); | ||
97 | mu_locus_range_copy (&np->locus, loc); | 98 | mu_locus_range_copy (&np->locus, loc); |
98 | p = (char*) (np + 1); | 99 | p = (char*) (np + 1); |
99 | np->tag = p; | 100 | np->tag = p; | ... | ... |
... | @@ -36,16 +36,10 @@ mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename) | ... | @@ -36,16 +36,10 @@ mu_locus_point_set_file (struct mu_locus_point *pt, const char *filename) |
36 | return 0; | 36 | return 0; |
37 | } | 37 | } |
38 | 38 | ||
39 | int | 39 | void |
40 | mu_locus_point_init (struct mu_locus_point *pt, const char *filename) | 40 | mu_locus_point_init (struct mu_locus_point *pt) |
41 | { | 41 | { |
42 | int rc = mu_locus_point_set_file (pt, filename); | 42 | memset (pt, 0, sizeof *pt); |
43 | if (rc == 0) | ||
44 | { | ||
45 | pt->mu_line = 0; | ||
46 | pt->mu_col = 0; | ||
47 | } | ||
48 | return rc; | ||
49 | } | 43 | } |
50 | 44 | ||
51 | void | 45 | void |
... | @@ -68,6 +62,12 @@ mu_locus_point_copy (struct mu_locus_point *dest, | ... | @@ -68,6 +62,12 @@ mu_locus_point_copy (struct mu_locus_point *dest, |
68 | return rc; | 62 | return rc; |
69 | } | 63 | } |
70 | 64 | ||
65 | void | ||
66 | mu_locus_range_init (struct mu_locus_range *dest) | ||
67 | { | ||
68 | memset (dest, 0, sizeof *dest); | ||
69 | } | ||
70 | |||
71 | int | 71 | int |
72 | mu_locus_range_copy (struct mu_locus_range *dest, | 72 | mu_locus_range_copy (struct mu_locus_range *dest, |
73 | struct mu_locus_range const *src) | 73 | struct mu_locus_range const *src) | ... | ... |
... | @@ -498,7 +498,7 @@ fmt_locus1 (mu_stream_t str) | ... | @@ -498,7 +498,7 @@ fmt_locus1 (mu_stream_t str) |
498 | { | 498 | { |
499 | char *file = "a"; | 499 | char *file = "a"; |
500 | mu_stream_printf (str, "\033f<%d>%s\033l<%d>one\n", | 500 | mu_stream_printf (str, "\033f<%d>%s\033l<%d>one\n", |
501 | strlen (file), file, 10); | 501 | (int) strlen (file), file, 10); |
502 | } | 502 | } |
503 | 503 | ||
504 | /* Check ESC-f, ESC-l, and ESC-c format specifiers. | 504 | /* Check ESC-f, ESC-l, and ESC-c format specifiers. |
... | @@ -510,7 +510,7 @@ fmt_locus2 (mu_stream_t str) | ... | @@ -510,7 +510,7 @@ fmt_locus2 (mu_stream_t str) |
510 | { | 510 | { |
511 | char *file = "a"; | 511 | char *file = "a"; |
512 | mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>one\n", | 512 | mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>one\n", |
513 | strlen (file), file, 10, 5); | 513 | (int) strlen (file), file, 10, 5); |
514 | } | 514 | } |
515 | 515 | ||
516 | /* Check setting range with ESC-f, ESC-l, and ESC-c format specifiers. | 516 | /* Check setting range with ESC-f, ESC-l, and ESC-c format specifiers. |
... | @@ -523,8 +523,8 @@ fmt_locus3 (mu_stream_t str) | ... | @@ -523,8 +523,8 @@ fmt_locus3 (mu_stream_t str) |
523 | char *file[] = { "a", "b" }; | 523 | char *file[] = { "a", "b" }; |
524 | mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>" | 524 | mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>" |
525 | "\033f<%d>%s\033l<%d>\033c<%d>one\n", | 525 | "\033f<%d>%s\033l<%d>\033c<%d>one\n", |
526 | strlen (file[0]), file[0], 10, 5, | 526 | (int) strlen (file[0]), file[0], 10, 5, |
527 | strlen (file[1]), file[1], 14, 8); | 527 | (int) strlen (file[1]), file[1], 14, 8); |
528 | } | 528 | } |
529 | 529 | ||
530 | /* Check that ESC-f, ESC-l, and ESC-c format specifiers don't clobber | 530 | /* Check that ESC-f, ESC-l, and ESC-c format specifiers don't clobber |
... | @@ -552,8 +552,8 @@ fmt_locus4 (mu_stream_t str) | ... | @@ -552,8 +552,8 @@ fmt_locus4 (mu_stream_t str) |
552 | 552 | ||
553 | mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>" | 553 | mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>" |
554 | "\033f<%d>%s\033l<%d>\033c<%d>one\n", | 554 | "\033f<%d>%s\033l<%d>\033c<%d>one\n", |
555 | strlen (file[0]), file[0], 10, 5, | 555 | (int) strlen (file[0]), file[0], 10, 5, |
556 | strlen (file[1]), file[1], 14, 8); | 556 | (int) strlen (file[1]), file[1], 14, 8); |
557 | mu_stream_printf (str, "default\n"); | 557 | mu_stream_printf (str, "default\n"); |
558 | } | 558 | } |
559 | 559 | ||
... | @@ -586,8 +586,8 @@ fmt_locus5 (mu_stream_t str) | ... | @@ -586,8 +586,8 @@ fmt_locus5 (mu_stream_t str) |
586 | MU_IOCTL_LOGSTREAM_SET_MODE, &mode); | 586 | MU_IOCTL_LOGSTREAM_SET_MODE, &mode); |
587 | mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>" | 587 | mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>" |
588 | "\033f<%d>%s\033l<%d>\033c<%d>one\n", | 588 | "\033f<%d>%s\033l<%d>\033c<%d>one\n", |
589 | strlen (file[0]), file[0], 10, 5, | 589 | (int) strlen (file[0]), file[0], 10, 5, |
590 | strlen (file[1]), file[1], 14, 8); | 590 | (int) strlen (file[1]), file[1], 14, 8); |
591 | mu_stream_printf (str, "default\n"); | 591 | mu_stream_printf (str, "default\n"); |
592 | } | 592 | } |
593 | 593 | ||
... | @@ -619,8 +619,8 @@ fmt_locus6 (mu_stream_t str) | ... | @@ -619,8 +619,8 @@ fmt_locus6 (mu_stream_t str) |
619 | MU_IOCTL_LOGSTREAM_SET_MODE, &mode); | 619 | MU_IOCTL_LOGSTREAM_SET_MODE, &mode); |
620 | mu_stream_printf (str, "\033S\033f<%d>%s\033l<%d>\033c<%d>" | 620 | mu_stream_printf (str, "\033S\033f<%d>%s\033l<%d>\033c<%d>" |
621 | "\033f<%d>%s\033l<%d>\033c<%d>one\n", | 621 | "\033f<%d>%s\033l<%d>\033c<%d>one\n", |
622 | strlen (file[0]), file[0], 10, 5, | 622 | (int) strlen (file[0]), file[0], 10, 5, |
623 | strlen (file[1]), file[1], 14, 8); | 623 | (int) strlen (file[1]), file[1], 14, 8); |
624 | mu_stream_printf (str, "default\n"); | 624 | mu_stream_printf (str, "default\n"); |
625 | } | 625 | } |
626 | 626 | ... | ... |
... | @@ -103,7 +103,7 @@ moderator_filter_message (mu_sieve_machine_t mach, | ... | @@ -103,7 +103,7 @@ moderator_filter_message (mu_sieve_machine_t mach, |
103 | } | 103 | } |
104 | else if (mu_sieve_get_tag (mach, "program", SVT_STRING, &arg)) | 104 | else if (mu_sieve_get_tag (mach, "program", SVT_STRING, &arg)) |
105 | { | 105 | { |
106 | struct mu_locus_range locrange; | 106 | struct mu_locus_range locrange = MU_LOCUS_RANGE_INITIALIZER; |
107 | 107 | ||
108 | rc = mu_sieve_machine_clone (mach, &newmach); | 108 | rc = mu_sieve_machine_clone (mach, &newmach); |
109 | if (rc) | 109 | if (rc) | ... | ... |
... | @@ -388,6 +388,7 @@ node_alloc (enum mu_sieve_node_type type, struct mu_locus_range *lr) | ... | @@ -388,6 +388,7 @@ node_alloc (enum mu_sieve_node_type type, struct mu_locus_range *lr) |
388 | { | 388 | { |
389 | node->prev = node->next = NULL; | 389 | node->prev = node->next = NULL; |
390 | node->type = type; | 390 | node->type = type; |
391 | mu_locus_range_init (&node->locus); | ||
391 | mu_locus_range_copy (&node->locus, lr); | 392 | mu_locus_range_copy (&node->locus, lr); |
392 | } | 393 | } |
393 | return node; | 394 | return node; |
... | @@ -1585,8 +1586,8 @@ mu_sieve_compile_buffer (mu_sieve_machine_t mach, | ... | @@ -1585,8 +1586,8 @@ mu_sieve_compile_buffer (mu_sieve_machine_t mach, |
1585 | const char *fname, int line) | 1586 | const char *fname, int line) |
1586 | { | 1587 | { |
1587 | int rc; | 1588 | int rc; |
1588 | struct mu_locus_point loc; | 1589 | struct mu_locus_point loc = MU_LOCUS_POINT_INITIALIZER; |
1589 | mu_locus_point_init (&loc, fname); | 1590 | mu_locus_point_set_file (&loc, fname); |
1590 | loc.mu_line = line; | 1591 | loc.mu_line = line; |
1591 | rc = mu_sieve_compile_text (mach, buf, bufsize, &loc); | 1592 | rc = mu_sieve_compile_text (mach, buf, bufsize, &loc); |
1592 | mu_locus_point_deinit (&loc); | 1593 | mu_locus_point_deinit (&loc); | ... | ... |
... | @@ -26,7 +26,7 @@ static char logger_args_doc[] = N_("[TEXT]"); | ... | @@ -26,7 +26,7 @@ static char logger_args_doc[] = N_("[TEXT]"); |
26 | static char *input_file = NULL; | 26 | static char *input_file = NULL; |
27 | static int logger_type = MU_STRERR_STDERR; | 27 | static int logger_type = MU_STRERR_STDERR; |
28 | static int log_severity = MU_LOG_ERROR; | 28 | static int log_severity = MU_LOG_ERROR; |
29 | static struct mu_locus_range locus; | 29 | static struct mu_locus_range locus = MU_LOCUS_RANGE_INITIALIZER; |
30 | static int syslog_facility = LOG_USER; | 30 | static int syslog_facility = LOG_USER; |
31 | static int syslog_priority = LOG_ERR; | 31 | static int syslog_priority = LOG_ERR; |
32 | static char *syslog_tag = NULL; | 32 | static char *syslog_tag = NULL; |
... | @@ -95,7 +95,7 @@ parse_locus_point (char **ptr, struct mu_locus_point *pt, | ... | @@ -95,7 +95,7 @@ parse_locus_point (char **ptr, struct mu_locus_point *pt, |
95 | char *end; | 95 | char *end; |
96 | *s++ = 0; | 96 | *s++ = 0; |
97 | if (*str) | 97 | if (*str) |
98 | mu_locus_point_init (pt, str); | 98 | mu_locus_point_set_file (pt, str); |
99 | pt->mu_line = strtoul (s, &end, 10); | 99 | pt->mu_line = strtoul (s, &end, 10); |
100 | if (end == s) | 100 | if (end == s) |
101 | { | 101 | { |
... | @@ -135,7 +135,7 @@ set_locus (struct mu_parseopt *po, struct mu_option *opt, | ... | @@ -135,7 +135,7 @@ set_locus (struct mu_parseopt *po, struct mu_option *opt, |
135 | parse_locus_point (&s, &locus.beg, po); | 135 | parse_locus_point (&s, &locus.beg, po); |
136 | if (*s == '-') | 136 | if (*s == '-') |
137 | { | 137 | { |
138 | mu_locus_point_init (&locus.end, locus.beg.mu_file); | 138 | mu_locus_point_set_file (&locus.end, locus.beg.mu_file); |
139 | locus.end.mu_line = locus.beg.mu_line; | 139 | locus.end.mu_line = locus.beg.mu_line; |
140 | locus.end.mu_col = locus.end.mu_col; | 140 | locus.end.mu_col = locus.end.mu_col; |
141 | s++; | 141 | s++; | ... | ... |
-
Please register or sign in to post a comment