summaryrefslogtreecommitdiffabout
path: root/src/main.c
authorSergey Poznyakoff <gray@gnu.org.ua>2011-03-09 09:00:12 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-03-09 09:47:52 (GMT)
commit30dfac6b8bc411481c9dd333bd8baab9e15c2d00 (patch) (unidiff)
tree08209280450a3c569f6d57088f97db482f956d40 /src/main.c
parentfedbf1d7be7a92ae10bd2e2c05f0bf5c10b933ce (diff)
downloadmailfromd-30dfac6b8bc411481c9dd333bd8baab9e15c2d00.tar.gz
mailfromd-30dfac6b8bc411481c9dd333bd8baab9e15c2d00.tar.bz2
Fix deferred variable initialization.
The bug was spotted by Brian Kroth. * src/gram.y (deferred_decl) <locus>: New member. (defer_initialize_variable): Use string_alloc instead of literal_lookup. Take additional argument (ptr to locus). All uses updated. (apply_deferred_init): Pass a ptr to the actual locus to initialize_variable. * src/mailfromd.h (defer_initialize_variable): Change signature. * src/main.c (cb_set_variable): Deduce definition location from mu_strerr. * THANKS: Update. * tests/setvar.at: New testcase. * tests/Makefile.am (TESTSUITE_AT): Add setvar.at. * tests/testsuite.at: Include setvar.at. * tests/invcidr.at: Update experr. * tests/invcidr2.at: Likewise.
Diffstat (limited to 'src/main.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/main.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 01fd14b..3d0264c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -550,6 +550,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
550 case 'v': 550 case 'v':
551 { 551 {
552 char *p; 552 char *p;
553 struct locus locus = { "<command line>", 1, 0 };
553 554
554 p = strchr(arg, '='); 555 p = strchr(arg, '=');
555 if (!p) 556 if (!p)
@@ -557,7 +558,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
557 _("expected assignment, but found `%s'"), 558 _("expected assignment, but found `%s'"),
558 arg); 559 arg);
559 *p++ = 0; 560 *p++ = 0;
560 defer_initialize_variable(arg, p); 561 defer_initialize_variable(arg, p, &locus);
561 break; 562 break;
562 } 563 }
563 564
@@ -716,7 +717,9 @@ cb_set_variable(void *data, mu_config_value_t *arg)
716{ 717{
717 const char *value; 718 const char *value;
718 char *alloc_str = NULL; 719 char *alloc_str = NULL;
719 720 struct mu_locus mloc;
721 struct locus locus;
722
720 if (mu_cfg_assert_value_type(arg, MU_CFG_ARRAY)) 723 if (mu_cfg_assert_value_type(arg, MU_CFG_ARRAY))
721 return 1; 724 return 1;
722 if (arg->v.arg.c < 2) { 725 if (arg->v.arg.c < 2) {
@@ -749,8 +752,25 @@ cb_set_variable(void *data, mu_config_value_t *arg)
749 __FILE__, __LINE__); 752 __FILE__, __LINE__);
750 abort(); 753 abort();
751 } 754 }
752 755
753 defer_initialize_variable(arg->v.arg.v[0].v.string, value); 756 locus.leng = 0;
757 if (mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
758 MU_IOCTL_LOGSTREAM_GET_LOCUS, &mloc)) {
759 locus.file = "<unknown>";
760 locus.line = 0;
761 locus.point = 0;
762 } else {
763 if (mloc.mu_file) {
764 struct literal *lit = string_alloc(mloc.mu_file,
765 strlen(mloc.mu_file));
766 free(mloc.mu_file);
767 locus.file = lit->text;
768 } else
769 locus.file = "<unknown>";
770 locus.line = mloc.mu_line;
771 locus.point = mloc.mu_col;
772 }
773 defer_initialize_variable(arg->v.arg.v[0].v.string, value, &locus);
754 free(alloc_str); 774 free(alloc_str);
755 return 0; 775 return 0;
756} 776}

Return to:

Send suggestions and report system problems to the System administrator.