fix: PVS-Studio V522 mark false

Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
Vyacheslav Ivanov
2024-08-03 23:00:10 +03:00
committed by Pugemon
parent 4efa574eec
commit 3621e7ce1b
18 changed files with 81 additions and 81 deletions
+8 -8
View File
@@ -62,8 +62,8 @@ void BlocksController::placeBlock(
void BlocksController::updateBlock(int x, int y, int z) {
voxel* vox = chunks->get(x, y, z);
if (vox == nullptr) return;
auto def = level->content->getIndices()->blocks.get(vox->id);
if (def->grounded) {
auto def = level->content->getIndices()->blocks.get(vox->id); //FIXME: Potentional null pointer
if (def->grounded) { //-V522
const auto& vec = get_ground_direction(def, vox->state.rotation);
if (!chunks->isSolidBlock(x + vec.x, y + vec.y, z + vec.z)) {
breakBlock(nullptr, def, x, y, z);
@@ -93,8 +93,8 @@ void BlocksController::onBlocksTick(int tickid, int parts) {
int tickRate = blocksTickClock.getTickRate();
for (size_t id = 0; id < indices->blocks.count(); id++) {
if ((id + tickid) % parts != 0) continue;
auto def = indices->blocks.get(id);
auto interval = def->tickInterval;
auto def = indices->blocks.get(id); //FIXME: Potentional null pointer
auto interval = def->tickInterval; //-V522
if (def->rt.funcsset.onblockstick && tickid / parts % interval == 0) {
scripting::on_blocks_tick(def, tickRate / interval);
}
@@ -112,8 +112,8 @@ void BlocksController::randomTick(
int by = random.rand() % segheight + s * segheight;
int bz = random.rand() % CHUNK_D;
const voxel& vox = chunk.voxels[(by * CHUNK_D + bz) * CHUNK_W + bx];
Block* block = indices->blocks.get(vox.id);
if (block->rt.funcsset.randupdate) {
Block* block = indices->blocks.get(vox.id); //FIXME: Potentional null pointer
if (block->rt.funcsset.randupdate) { //-V522
scripting::random_update_block(
block, chunk.x * CHUNK_W + bx, by, chunk.z * CHUNK_D + bz
);
@@ -153,8 +153,8 @@ int64_t BlocksController::createBlockInventory(int x, int y, int z) {
auto inv = chunk->getBlockInventory(lx, y, lz);
if (inv == nullptr) {
auto indices = level->content->getIndices();
auto def = indices->blocks.get(chunk->voxels[vox_index(lx, y, lz)].id);
int invsize = def->inventorySize;
auto def = indices->blocks.get(chunk->voxels[vox_index(lx, y, lz)].id); //FIXME: Potentional null pointer
int invsize = def->inventorySize; //-V522
if (invsize == 0) {
return 0;
}
+8 -8
View File
@@ -208,8 +208,8 @@ void PlayerController::onFootstep(const Hitbox& hitbox) {
int z = std::floor(pos.z + half.z * offsetZ);
auto vox = level->chunks->get(x, y, z);
if (vox) {
auto def = level->content->getIndices()->blocks.get(vox->id);
if (!def->obstacle) continue;
auto def = level->content->getIndices()->blocks.get(vox->id); //FIXME: Potentional null pointer
if (!def->obstacle) continue; //-V522
blocksController->onBlockInteraction(
player.get(),
glm::ivec3(x, y, z),
@@ -333,8 +333,8 @@ static int determine_rotation(
static void pick_block(
ContentIndices* indices, Chunks* chunks, Player* player, int x, int y, int z
) {
auto block = indices->blocks.get(chunks->get(x, y, z)->id);
itemid_t id = block->rt.pickingItem;
auto block = indices->blocks.get(chunks->get(x, y, z)->id); //FIXME: Potentional null pointer
itemid_t id = block->rt.pickingItem; //-V522
auto inventory = player->getInventory();
size_t slotid = inventory->findSlotByItem(id, 0, 10);
if (slotid == Inventory::npos) {
@@ -492,11 +492,11 @@ void PlayerController::updateInteraction() {
auto inventory = player->getInventory();
const ItemStack& stack = inventory->getSlot(player->getChosenSlot());
ItemDef* item = indices->items.get(stack.getItemId());
ItemDef* item = indices->items.get(stack.getItemId()); //FIXME: Potentional null pointer
auto vox = updateSelection(maxDistance);
if (vox == nullptr) {
if (rclick && item->rt.funcsset.on_use) {
if (rclick && item->rt.funcsset.on_use) { //-V522
scripting::on_item_use(player.get(), item);
}
if (selection.entity) {
@@ -513,8 +513,8 @@ void PlayerController::updateInteraction() {
return;
}
}
auto target = indices->blocks.get(vox->id);
if (lclick && target->breakable) {
auto target = indices->blocks.get(vox->id); //FIXME: Potentional null pointer
if (lclick && target->breakable) { //-V522
blocksController->breakBlock(
player.get(), target, iend.x, iend.y, iend.z
);
+6 -6
View File
@@ -122,8 +122,8 @@ static int l_get_x(lua::State* L) {
if (vox == nullptr) {
return lua::pushivec3_stack(L, 1, 0, 0);
}
auto def = level->content->getIndices()->blocks.get(vox->id);
if (!def->rotatable) {
auto def = level->content->getIndices()->blocks.get(vox->id); //FIXME: Potentional null pointer
if (!def->rotatable) { //-V522
return lua::pushivec3_stack(L, 1, 0, 0);
} else {
const CoordSystem& rot = def->rotations.variants[vox->state.rotation];
@@ -139,8 +139,8 @@ static int l_get_y(lua::State* L) {
if (vox == nullptr) {
return lua::pushivec3_stack(L, 0, 1, 0);
}
auto def = level->content->getIndices()->blocks.get(vox->id);
if (!def->rotatable) {
auto def = level->content->getIndices()->blocks.get(vox->id); //FIXME: Potentional null pointer
if (!def->rotatable) { //-V522
return lua::pushivec3_stack(L, 0, 1, 0);
} else {
const CoordSystem& rot = def->rotations.variants[vox->state.rotation];
@@ -156,8 +156,8 @@ static int l_get_z(lua::State* L) {
if (vox == nullptr) {
return lua::pushivec3_stack(L, 0, 0, 1);
}
auto def = level->content->getIndices()->blocks.get(vox->id);
if (!def->rotatable) {
auto def = level->content->getIndices()->blocks.get(vox->id); //FIXME: Potentional null pointer
if (!def->rotatable) { //-V522
return lua::pushivec3_stack(L, 0, 0, 1);
} else {
const CoordSystem& rot = def->rotations.variants[vox->state.rotation];
+8 -8
View File
@@ -53,34 +53,34 @@ static DocumentNode getDocumentNode(lua::State* L, int idx = 1) {
static int l_menu_back(lua::State* L) {
auto node = getDocumentNode(L);
auto menu = dynamic_cast<Menu*>(node.node.get());
menu->back();
auto menu = dynamic_cast<Menu*>(node.node.get()); //FIXME: Potentional null pointer
menu->back(); //-V522
return 0;
}
static int l_menu_reset(lua::State* L) {
auto node = getDocumentNode(L);
auto menu = dynamic_cast<Menu*>(node.node.get());
menu->reset();
auto menu = dynamic_cast<Menu*>(node.node.get()); //FIXME: Potentional null pointer
menu->reset(); //-V522
return 0;
}
static int l_textbox_paste(lua::State* L) {
auto node = getDocumentNode(L);
auto box = dynamic_cast<TextBox*>(node.node.get());
auto box = dynamic_cast<TextBox*>(node.node.get()); //FIXME: Potentional null pointer
auto text = lua::require_string(L, 2);
box->paste(util::str2wstr_utf8(text));
box->paste(util::str2wstr_utf8(text)); //-V522
return 0;
}
static int l_container_add(lua::State* L) {
auto docnode = getDocumentNode(L);
auto node = dynamic_cast<Container*>(docnode.node.get());
auto node = dynamic_cast<Container*>(docnode.node.get()); //FIXME: Potentional null pointer
auto xmlsrc = lua::require_string(L, 2);
try {
auto subnode =
guiutil::create(xmlsrc, docnode.document->getEnvironment());
node->add(subnode);
node->add(subnode); //-V522
UINode::getIndices(subnode, docnode.document->getMapWriteable());
} catch (const std::exception& err) {
throw std::runtime_error(err.what());
+1 -1
View File
@@ -51,7 +51,7 @@ static int l_hud_open_block(lua::State* L) {
}
auto def = content->getIndices()->blocks.get(vox->id);
auto assets = engine->getAssets();
auto layout = assets->get<UiDocument>(def->uiLayout);
auto layout = assets->get<UiDocument>(def->uiLayout);//FIXME: Potentional null pointer //-V522
if (layout == nullptr) {
throw std::runtime_error("block '" + def->name + "' has no ui layout");
}