Hello,

In my opinion, node.has_attribute behaves wrongly when the attribute number passed as parameter is nil. Since the attribute number is incorrect, it should return nil; but it returns a valid result.

  This is the current code in lnodelib.c :
====================
static int lua_nodelib_has_attribute(lua_State * L)
{
    halfword *n;
    int i, val;
    n = check_isnode(L, 1);
    if (n != NULL) {
        i = (int) lua_tointeger(L, 2);
        val = (int) luaL_optinteger(L, 3, UNUSED_ATTRIBUTE);
        if ((val = has_attribute(*n, i, val)) > UNUSED_ATTRIBUTE) {
            lua_pushnumber(L, val);
            return 1;
        }
    }
    lua_pushnil(L);
    return 1;
}
=====================

lua_tointeger() may return anything if the parameter is not an integer. So a check should be added before calling lua_tointeger(). I am not sure if the exact integer correctness should be tested, but I think it should be at least tested against nil.


Goodbye,
  Stéphane Goujet.

Reply via email to