refactor: PVS-Studio warnings fixes
This commit is contained in:
@@ -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); //FIXME: Potentional null pointer
|
||||
int invsize = def->inventorySize; //-V522
|
||||
auto& def = indices->blocks.require(chunk->voxels[vox_index(lx, y, lz)].id);
|
||||
int invsize = def.inventorySize;
|
||||
if (invsize == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -335,8 +335,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); //FIXME: Potentional null pointer
|
||||
itemid_t id = block->rt.pickingItem; //-V522
|
||||
auto& block = indices->blocks.require(chunks->get(x, y, z)->id);
|
||||
itemid_t id = block.rt.pickingItem;
|
||||
auto inventory = player->getInventory();
|
||||
size_t slotid = inventory->findSlotByItem(id, 0, 10);
|
||||
if (slotid == Inventory::npos) {
|
||||
|
||||
@@ -119,11 +119,11 @@ 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); //FIXME: Potentional null pointer
|
||||
if (!def->rotatable) { //-V522
|
||||
auto& def = level->content->getIndices()->blocks.require(vox->id);
|
||||
if (!def.rotatable) {
|
||||
return lua::pushivec3_stack(L, 1, 0, 0);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->state.rotation];
|
||||
const CoordSystem& rot = def.rotations.variants[vox->state.rotation];
|
||||
return lua::pushivec3_stack(L, rot.axisX.x, rot.axisX.y, rot.axisX.z);
|
||||
}
|
||||
}
|
||||
@@ -136,11 +136,11 @@ 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); //FIXME: Potentional null pointer
|
||||
if (!def->rotatable) { //-V522
|
||||
auto& def = level->content->getIndices()->blocks.require(vox->id);
|
||||
if (!def.rotatable) {
|
||||
return lua::pushivec3_stack(L, 0, 1, 0);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->state.rotation];
|
||||
const CoordSystem& rot = def.rotations.variants[vox->state.rotation];
|
||||
return lua::pushivec3_stack(L, rot.axisY.x, rot.axisY.y, rot.axisY.z);
|
||||
}
|
||||
}
|
||||
@@ -153,11 +153,11 @@ 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); //FIXME: Potentional null pointer
|
||||
if (!def->rotatable) { //-V522
|
||||
auto& def = level->content->getIndices()->blocks.require(vox->id);
|
||||
if (!def.rotatable) {
|
||||
return lua::pushivec3_stack(L, 0, 0, 1);
|
||||
} else {
|
||||
const CoordSystem& rot = def->rotations.variants[vox->state.rotation];
|
||||
const CoordSystem& rot = def.rotations.variants[vox->state.rotation];
|
||||
return lua::pushivec3_stack(L, rot.axisZ.x, rot.axisZ.y, rot.axisZ.z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,34 +53,40 @@ 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()); //FIXME: Potentional null pointer
|
||||
menu->back(); //-V522
|
||||
if (auto menu = dynamic_cast<Menu*>(node.node.get())) {
|
||||
menu->back();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_menu_reset(lua::State* L) {
|
||||
auto node = getDocumentNode(L);
|
||||
auto menu = dynamic_cast<Menu*>(node.node.get()); //FIXME: Potentional null pointer
|
||||
menu->reset(); //-V522
|
||||
if (auto menu = dynamic_cast<Menu*>(node.node.get())) {
|
||||
menu->reset();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_textbox_paste(lua::State* L) {
|
||||
auto node = getDocumentNode(L);
|
||||
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)); //-V522
|
||||
if (auto box = dynamic_cast<TextBox*>(node.node.get())) {
|
||||
auto text = lua::require_string(L, 2);
|
||||
box->paste(util::str2wstr_utf8(text));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_container_add(lua::State* L) {
|
||||
auto docnode = getDocumentNode(L);
|
||||
auto node = dynamic_cast<Container*>(docnode.node.get()); //FIXME: Potentional null pointer
|
||||
auto node = dynamic_cast<Container*>(docnode.node.get());
|
||||
if (node == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
auto xmlsrc = lua::require_string(L, 2);
|
||||
try {
|
||||
auto subnode =
|
||||
guiutil::create(xmlsrc, docnode.document->getEnvironment());
|
||||
node->add(subnode); //-V522
|
||||
node->add(subnode);
|
||||
UINode::getIndices(subnode, docnode.document->getMapWriteable());
|
||||
} catch (const std::exception& err) {
|
||||
throw std::runtime_error(err.what());
|
||||
|
||||
@@ -49,11 +49,11 @@ static int l_hud_open_block(lua::State* L) {
|
||||
std::to_string(y) + " " + std::to_string(z)
|
||||
);
|
||||
}
|
||||
auto def = content->getIndices()->blocks.get(vox->id);
|
||||
auto& def = content->getIndices()->blocks.require(vox->id);
|
||||
auto assets = engine->getAssets();
|
||||
auto layout = assets->get<UiDocument>(def->uiLayout);//FIXME: Potentional null pointer //-V522
|
||||
auto layout = assets->get<UiDocument>(def.uiLayout);
|
||||
if (layout == nullptr) {
|
||||
throw std::runtime_error("block '" + def->name + "' has no ui layout");
|
||||
throw std::runtime_error("block '" + def.name + "' has no ui layout");
|
||||
}
|
||||
|
||||
auto id = blocks->createBlockInventory(x, y, z);
|
||||
@@ -65,7 +65,7 @@ static int l_hud_open_block(lua::State* L) {
|
||||
);
|
||||
|
||||
lua::pushinteger(L, id);
|
||||
lua::pushstring(L, def->uiLayout);
|
||||
lua::pushstring(L, def.uiLayout);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user