Skip to content

Commit

Permalink
Don't push directly the result of bitwise operations with lua_pushboo…
Browse files Browse the repository at this point in the history
…lean

Explicitly check for !=0 to avoid possible future oversights caused by the integers being changed becoming 64 bit
  • Loading branch information
edo9300 committed Aug 12, 2023
1 parent 97b31cb commit 70f4194
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions libcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ LUA_FUNCTION(IsOriginalType) {
check_param_count(L, 2);
auto pcard = lua_get<card*, true>(L, 1);
auto ttype = lua_get<uint32_t>(L, 2);
lua_pushboolean(L, pcard->data.type & ttype);
lua_pushboolean(L, (pcard->data.type & ttype) != 0);
return 1;
}
inline int32_t is_prop(lua_State* L, uint32_t val) {
Expand Down Expand Up @@ -989,14 +989,14 @@ LUA_FUNCTION(IsOriginalAttribute) {
if(pcard->status & STATUS_NO_LEVEL)
lua_pushboolean(L, FALSE);
else
lua_pushboolean(L, pcard->data.attribute & tattrib);
lua_pushboolean(L, (pcard->data.attribute & tattrib) != 0);
return 1;
}
LUA_FUNCTION(IsReason) {
check_param_count(L, 2);
auto pcard = lua_get<card*, true>(L, 1);
auto treason = lua_get<uint32_t>(L, 2);
lua_pushboolean(L, pcard->current.reason & treason);
lua_pushboolean(L, (pcard->current.reason & treason) != 0);
return 1;
}
LUA_FUNCTION(IsSummonType) {
Expand Down Expand Up @@ -1029,7 +1029,7 @@ LUA_FUNCTION(IsStatus) {
check_param_count(L, 2);
auto pcard = lua_get<card*, true>(L, 1);
auto tstatus = lua_get<uint32_t>(L, 2);
lua_pushboolean(L, pcard->status & tstatus);
lua_pushboolean(L, (pcard->status & tstatus) != 0);
return 1;
}
LUA_FUNCTION(IsNotTuner) {
Expand Down Expand Up @@ -1973,7 +1973,7 @@ LUA_FUNCTION(IsPreviousPosition) {
check_param_count(L, 2);
auto pcard = lua_get<card*, true>(L, 1);
auto pos = lua_get<uint8_t>(L, 2);
lua_pushboolean(L, pcard->previous.position & pos);
lua_pushboolean(L, (pcard->previous.position & pos) != 0);
return 1;
}
LUA_FUNCTION(IsControler) {
Expand Down Expand Up @@ -2015,7 +2015,7 @@ LUA_FUNCTION(IsLocation) {
else
lua_pushboolean(L, 0);
} else
lua_pushboolean(L, pcard->current.location & loc);
lua_pushboolean(L, (pcard->current.location & loc) != 0);
return 1;
}
LUA_FUNCTION(IsPreviousLocation) {
Expand Down Expand Up @@ -2541,7 +2541,7 @@ LUA_FUNCTION(GetAttackableTarget) {
pduel->game_field->get_attack_target(pcard, &targets, chain_attack);
group* newgroup = pduel->new_group(targets);
interpreter::pushobject(L, newgroup);
lua_pushboolean(L, (int32_t)pcard->direct_attackable);
lua_pushboolean(L, pcard->direct_attackable);
return 2;
}
LUA_FUNCTION(SetHint) {
Expand Down
8 changes: 4 additions & 4 deletions libeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ LUA_FUNCTION(GetActiveType) {
LUA_FUNCTION(IsActiveType) {
check_param_count(L, 2);
auto peffect = lua_get<effect*, true>(L, 1);
lua_pushboolean(L, peffect->get_active_type() & lua_get<uint32_t>(L, 2));
lua_pushboolean(L, (peffect->get_active_type() & lua_get<uint32_t>(L, 2)) != 0);
return 1;
}
LUA_FUNCTION(IsHasProperty) {
Expand All @@ -476,13 +476,13 @@ LUA_FUNCTION(IsHasProperty) {
LUA_FUNCTION(IsHasCategory) {
check_param_count(L, 2);
auto peffect = lua_get<effect*, true>(L, 1);
lua_pushboolean(L, peffect->category & lua_get<uint32_t>(L, 2));
lua_pushboolean(L, (peffect->category & lua_get<uint32_t>(L, 2)) != 0);
return 1;
}
LUA_FUNCTION(IsHasType) {
check_param_count(L, 2);
auto peffect = lua_get<effect*, true>(L, 1);
lua_pushboolean(L, peffect->type & lua_get<uint16_t>(L, 2));
lua_pushboolean(L, (peffect->type & lua_get<uint16_t>(L, 2)) != 0);
return 1;
}
LUA_FUNCTION(IsActivatable) {
Expand All @@ -498,7 +498,7 @@ LUA_FUNCTION(IsActivatable) {
LUA_FUNCTION(IsActivated) {
check_param_count(L, 1);
auto peffect = lua_get<effect*, true>(L, 1);
lua_pushboolean(L, (peffect->type & 0x7f0));
lua_pushboolean(L, (peffect->type & 0x7f0) != 0);
return 1;
}
LUA_FUNCTION(GetActivateLocation) {
Expand Down

0 comments on commit 70f4194

Please sign in to comment.