Merge branch 'fix_uninit' into 'master'

Fix uninitialized coverity warnings

See merge request OpenMW/openmw!1819
pull/3227/head
jvoisin 3 years ago
commit 331363d469

@ -11,9 +11,9 @@ namespace EsmTool
struct Arguments
{
std::optional<ESM::Format> mRawFormat;
bool quiet_given;
bool loadcells_given;
bool plain_given;
bool quiet_given = false;
bool loadcells_given = false;
bool plain_given = false;
std::string mode;
std::string encoding;

@ -36,11 +36,7 @@ namespace bpo = boost::program_options;
struct ESMData
{
std::string author;
std::string description;
unsigned int version;
std::vector<ESM::Header::MasterData> masters;
ESM::Header mHeader;
std::deque<std::unique_ptr<EsmTool::RecordBase>> mRecords;
// Value: (Reference, Deleted flag)
std::map<ESM::Cell *, std::deque<std::pair<ESM::CellRef, bool> > > mCellRefs;
@ -331,11 +327,7 @@ int loadTes3(const Arguments& info, std::unique_ptr<std::ifstream>&& stream, ESM
esm.open(std::move(stream), info.filename);
if (data != nullptr)
{
data->author = esm.getAuthor();
data->description = esm.getDesc();
data->masters = esm.getGameFiles();
}
data->mHeader = esm.getHeader();
if (!quiet)
{
@ -503,14 +495,10 @@ int clone(const Arguments& info)
ESM::ESMWriter esm;
ToUTF8::Utf8Encoder encoder (ToUTF8::calculateEncoding(info.encoding));
esm.setEncoder(&encoder);
esm.setAuthor(data.author);
esm.setDescription(data.description);
esm.setVersion(data.version);
esm.setHeader(data.mHeader);
esm.setVersion(ESM::VER_13);
esm.setRecordCount (recordCount);
for (const ESM::Header::MasterData &master : data.masters)
esm.addMaster(master.name, master.size);
std::fstream save(info.outname.c_str(), std::fstream::out | std::fstream::binary);
esm.save(save);

@ -38,6 +38,7 @@ class ESMWriter
void setEncoder(ToUTF8::Utf8Encoder *encoding);
void setAuthor(const std::string& author);
void setDescription(const std::string& desc);
void setHeader(const Header& value) { mHeader = value; }
// Set the record count for writing it in the file header
void setRecordCount (int count);

@ -158,6 +158,9 @@ namespace ESM
npdt12.mDisposition = mNpdt.mDisposition;
npdt12.mReputation = mNpdt.mReputation;
npdt12.mRank = mNpdt.mRank;
npdt12.mUnknown1 = 0;
npdt12.mUnknown2 = 0;
npdt12.mUnknown3 = 0;
npdt12.mGold = mNpdt.mGold;
esm.writeHNT("NPDT", npdt12, 12);
}

@ -27,6 +27,7 @@
#include "loadhdpt.hpp"
#include <stdexcept>
#include <optional>
//#include <iostream> // FIXME: testing only
#include "reader.hpp"
@ -38,7 +39,7 @@ void ESM4::HeadPart::load(ESM4::Reader& reader)
reader.adjustFormId(mFormId);
mFlags = reader.hdr().record.flags;
std::uint32_t type;
std::optional<std::uint32_t> type;
while (reader.getSubRecordHeader())
{
@ -52,7 +53,9 @@ void ESM4::HeadPart::load(ESM4::Reader& reader)
case ESM4::SUB_HNAM: reader.getFormId(mAdditionalPart); break;
case ESM4::SUB_NAM0: // TES5
{
reader.get(type);
std::uint32_t value;
reader.get(value);
type = value;
break;
}
@ -61,8 +64,13 @@ void ESM4::HeadPart::load(ESM4::Reader& reader)
std::string file;
reader.getZString(file);
// FIXME: check type >= 0 && type < 3
mTriFile[type] = std::move(file);
if (!type.has_value())
throw std::runtime_error("Failed to read ESM4 HDPT record: subrecord NAM0 does not precede subrecord NAM1: file type is unknown");
if (*type >= mTriFile.size())
throw std::runtime_error("Failed to read ESM4 HDPT record: invalid file type: " + std::to_string(*type));
mTriFile[*type] = std::move(file);
break;
}

@ -58,6 +58,7 @@ void ESM4::Land::load(ESM4::Reader& reader)
mFormId = reader.hdr().record.id;
reader.adjustFormId(mFormId);
mFlags = reader.hdr().record.flags;
mDataTypes = 0;
TxtLayer layer;
std::int8_t currentAddQuad = -1; // for VTXT following ATXT

@ -65,18 +65,20 @@ void ESM4::Quest::load(ESM4::Reader& reader)
case ESM4::SUB_SCRI: reader.get(mQuestScript); break;
case ESM4::SUB_CTDA: // FIXME: how to detect if 1st/2nd param is a formid?
{
TargetCondition cond;
if (subHdr.dataSize == 24) // TES4
{
TargetCondition cond;
reader.get(&cond, 24);
cond.reference = 0; // unused in TES4 but keep it clean
mTargetConditions.push_back(cond);
}
else if (subHdr.dataSize == 28)
{
TargetCondition cond;
reader.get(cond); // FO3/FONV
if (cond.reference)
reader.adjustFormId(cond.reference);
mTargetConditions.push_back(cond);
}
else
{
@ -85,8 +87,6 @@ void ESM4::Quest::load(ESM4::Reader& reader)
}
// FIXME: support TES5
mTargetConditions.push_back(cond);
break;
}
case ESM4::SUB_SCHR: reader.get(mScript.scriptHeader); break;

@ -66,7 +66,7 @@ void ESM4::Header::load(ESM4::Reader& reader)
throw std::runtime_error("TES4 MAST data read error");
// NOTE: some mods do not have DATA following MAST so can't read DATA here
m.size = 0;
mMaster.push_back (m);
break;
}

Loading…
Cancel
Save