mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05: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.
This commit is contained in:
parent
9e52956a02
commit
8766e3829f
@ -225,6 +225,11 @@ num_rd(struct option *opt, unsigned char **file, int *line)
|
||||
static int
|
||||
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);
|
||||
return 1;
|
||||
}
|
||||
|
@ -502,21 +502,21 @@ l_set_option(LS)
|
||||
switch (opt->type) {
|
||||
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));
|
||||
break;
|
||||
}
|
||||
case OPT_INT:
|
||||
{
|
||||
int value = lua_tonumber(S, 2);
|
||||
option_types[opt->type].set(opt, (unsigned char *) (&value));
|
||||
break;
|
||||
}
|
||||
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);
|
||||
|
||||
option_types[opt->type].set(opt, (unsigned char *) (&value));
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user