1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-30 03:26:23 -04:00

bug 764, LUA: option_types[OPT_INT].set needs long *

l_set_option() was passing the address of an int to
option_types[OPT_INT].set and option_types[OPT_BOOL].set.
That looks correct but is not: both function pointers
point to num_set(), which actually reads *(long *) str.
Change l_set_option() to pass the address of a long instead,
and add comments about this dependency.
(cherry picked from elinks-0.11 commit 8766e3829f)
(cherry picked from elinks-0.12 commit 0797f04921)
This commit is contained in:
Kalle Olavi Niemitalo 2009-08-20 22:44:46 +03:00 committed by Kalle Olavi Niemitalo
parent 237d30b936
commit 9e11e30fe3
2 changed files with 12 additions and 7 deletions

View File

@ -225,6 +225,11 @@ num_rd(struct option *opt, unsigned char **file, int *line)
static int static int
num_set(struct option *opt, unsigned char *str) num_set(struct option *opt, unsigned char *str)
{ {
/* In num_rd(), num_set(), and num_eq(), str always points
* to a long, even though these functions are only used for
* OPT_BOOL and OPT_INT, which use int option_value.number.
* redir_rd(), redir_set(), and redir_eq() expect this.
* So does l_set_option() in the Lua scripting backend. */
opt->value.number = *((long *) str); opt->value.number = *((long *) str);
return 1; return 1;
} }

View File

@ -519,21 +519,21 @@ l_set_option(LS)
switch (opt->type) { switch (opt->type) {
case OPT_BOOL: case OPT_BOOL:
{ {
int value; /* option_types[OPT_BOOL].set expects a long even though it
* saves the value to opt->value.number, which is an int. */
long value = lua_toboolean(S, 2);
value = lua_toboolean(S, 2);
option_types[opt->type].set(opt, (unsigned char *) (&value)); option_types[opt->type].set(opt, (unsigned char *) (&value));
break; break;
} }
case OPT_INT: case OPT_INT:
{
int value = lua_tonumber(S, 2);
option_types[opt->type].set(opt, (unsigned char *) (&value));
break;
}
case OPT_LONG: case OPT_LONG:
{ {
/* option_types[OPT_INT].set expects a long even though it
* saves the value to opt->value.number, which is an int.
* option_types[OPT_LONG].set of course wants a long too. */
long value = lua_tonumber(S, 2); long value = lua_tonumber(S, 2);
option_types[opt->type].set(opt, (unsigned char *) (&value)); option_types[opt->type].set(opt, (unsigned char *) (&value));
break; break;
} }