Lua: Improve base checking for signed integer

Check base value for signed integer before unsigned to avoid a case
where the valid bases for a unsigned integer is presented in a error
message when a signed type is used.

Change-Id: Idfb87597779652e32adceacad220d748afda5e85
Reviewed-on: https://code.wireshark.org/review/20541
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
Stig Bjørlykke 2017-03-14 10:33:29 +01:00 committed by Peter Wu
parent d89bb12d1f
commit c899dd57ff
1 changed files with 9 additions and 9 deletions

View File

@ -495,15 +495,15 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) {
base = BASE_OCT; /* default base for characters (BASE_HEX instead?) */
else
base = BASE_DEC; /* Default base for integer */
} else if (base < BASE_DEC || base > BASE_HEX_DEC) {
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be either base.DEC, base.HEX, base.OCT,"
" base.DEC_HEX, base.HEX_DEC or base.UNIT_STRING");
return 0;
}
if ((base != BASE_DEC) &&
(type == FT_INT8 || type == FT_INT16 || type == FT_INT24 || type == FT_INT32 || type == FT_INT64))
{
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be base.DEC or base.UNIT_STRING for signed integer");
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be either base.DEC or base.UNIT_STRING");
return 0;
} else if (base < BASE_DEC || base > BASE_HEX_DEC) {
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be either base.DEC, base.HEX, base.OCT,"
" base.DEC_HEX, base.HEX_DEC or base.UNIT_STRING");
return 0;
}
if (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING &&
@ -698,14 +698,14 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
luaL_argerror(L, 3, "FRAMENUM must use base.NONE");
else if (mask)
luaL_argerror(L, 5, "FRAMENUM can not have a bitmask");
} else if ((base != BASE_DEC) &&
(type == FT_INT8 || type == FT_INT16 || type == FT_INT24 || type == FT_INT32 || type == FT_INT64)) {
luaL_argerror(L, 3, "Base must be either base.DEC or base.UNIT_STRING");
return 0;
} else if (base < BASE_DEC || base > BASE_HEX_DEC) {
luaL_argerror(L, 3, "Base must be either base.DEC, base.HEX, base.OCT,"
" base.DEC_HEX, base.HEX_DEC or base.UNIT_STRING");
return 0;
} else if ((base != BASE_DEC) &&
(type == FT_INT8 || type == FT_INT16 || type == FT_INT24 || type == FT_INT32 || type == FT_INT64)) {
luaL_argerror(L, 3, "Base must be base.DEC or base.UNIT_STRING for signed integer");
return 0;
}
f = g_new(wslua_field_t,1);