summaryrefslogtreecommitdiffabout
path: root/src
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) (side-by-side diff)
tree08209280450a3c569f6d57088f97db482f956d40 /src
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') (more/less context) (ignore whitespace changes)
-rw-r--r--src/gram.y19
-rw-r--r--src/mailfromd.h3
-rw-r--r--src/main.c28
3 files changed, 38 insertions, 12 deletions
diff --git a/src/gram.y b/src/gram.y
index be8dc2f..990fa13 100644
--- a/src/gram.y
+++ b/src/gram.y
@@ -3757,27 +3757,31 @@ struct deferred_decl {
struct deferred_decl *next;
struct literal *name;
struct value value;
+ struct locus locus;
};
struct deferred_decl *deferred_decl;
void
-defer_initialize_variable(const char *arg, const char *val)
+defer_initialize_variable(const char *arg, const char *val,
+ struct locus *ploc)
{
struct deferred_decl *p;
- struct literal *name = literal_lookup(arg);
+ struct literal *name = string_alloc(arg, strlen(arg));
for (p = deferred_decl; p; p = p->next)
if (p->name == name) {
parse_warning_locus(NULL, _("redefining variable %s"),
name->text);
p->value.type = dtype_string;
- p->value.v.literal = literal_lookup(val);
+ p->value.v.literal = string_alloc(val, strlen(val));
+ p->locus = *ploc;
return;
}
p = xmalloc(sizeof *p);
p->name = name;
p->value.type = dtype_string;
- p->value.v.literal = literal_lookup(val);
+ p->value.v.literal = string_alloc(val, strlen(val));
+ p->locus = *ploc;
p->next = deferred_decl;
deferred_decl = p;
}
@@ -3794,9 +3798,10 @@ apply_deferred_init()
p->name->text);
continue;
}
- if (initialize_variable(var, &p->value, NULL))
- mu_error(_("error initialising variable %s: incompatible types"),
- p->name->text);
+ if (initialize_variable(var, &p->value, &p->locus))
+ parse_error_locus(&p->locus,
+ _("error initialising variable %s: incompatible types"),
+ p->name->text);
}
}
diff --git a/src/mailfromd.h b/src/mailfromd.h
index e45f26e..7be3fab 100644
--- a/src/mailfromd.h
+++ b/src/mailfromd.h
@@ -573,7 +573,8 @@ struct variable *builtin_variable_install(const char *name,
data_type_t type,
unsigned flags,
size_t *addrptr);
-void defer_initialize_variable(const char *arg, const char *val);
+void defer_initialize_variable(const char *arg, const char *val,
+ struct locus *locus);
int variable_or_constant_lookup(const char *name, void **dptr);
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)
case 'v':
{
char *p;
+ struct locus locus = { "<command line>", 1, 0 };
p = strchr(arg, '=');
if (!p)
@@ -557,7 +558,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
_("expected assignment, but found `%s'"),
arg);
*p++ = 0;
- defer_initialize_variable(arg, p);
+ defer_initialize_variable(arg, p, &locus);
break;
}
@@ -716,7 +717,9 @@ cb_set_variable(void *data, mu_config_value_t *arg)
{
const char *value;
char *alloc_str = NULL;
-
+ struct mu_locus mloc;
+ struct locus locus;
+
if (mu_cfg_assert_value_type(arg, MU_CFG_ARRAY))
return 1;
if (arg->v.arg.c < 2) {
@@ -749,8 +752,25 @@ cb_set_variable(void *data, mu_config_value_t *arg)
__FILE__, __LINE__);
abort();
}
-
- defer_initialize_variable(arg->v.arg.v[0].v.string, value);
+
+ locus.leng = 0;
+ if (mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_GET_LOCUS, &mloc)) {
+ locus.file = "<unknown>";
+ locus.line = 0;
+ locus.point = 0;
+ } else {
+ if (mloc.mu_file) {
+ struct literal *lit = string_alloc(mloc.mu_file,
+ strlen(mloc.mu_file));
+ free(mloc.mu_file);
+ locus.file = lit->text;
+ } else
+ locus.file = "<unknown>";
+ locus.line = mloc.mu_line;
+ locus.point = mloc.mu_col;
+ }
+ defer_initialize_variable(arg->v.arg.v[0].v.string, value, &locus);
free(alloc_str);
return 0;
}

Return to:

Send suggestions and report system problems to the System administrator.