diff --git a/src/config/opttypes.c b/src/config/opttypes.c index e79e42f0..ea308041 100644 --- a/src/config/opttypes.c +++ b/src/config/opttypes.c @@ -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; } diff --git a/src/scripting/lua/core.c b/src/scripting/lua/core.c index 8aec3a91..bff037bd 100644 --- a/src/scripting/lua/core.c +++ b/src/scripting/lua/core.c @@ -517,21 +517,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; }