refactor: PVS-Studio warnings fixes

This commit is contained in:
MihailRis
2024-08-04 01:30:52 +03:00
parent 245b39be62
commit 47db626145
14 changed files with 81 additions and 69 deletions
+9 -9
View File
@@ -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);
}
}
+15 -9
View File
@@ -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());
+4 -4
View File
@@ -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;
}