Skip to content

Commit

Permalink
warnings and debug code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Dec 26, 2023
1 parent 133b415 commit 9583035
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/common/filesystem/include/resourcefile.h
Expand Up @@ -190,7 +190,7 @@ class FResourceFile
return (entry < NumLumps) ? Entries[entry].FileName : nullptr;
}

virtual FileData Read(int entry);
virtual FileData Read(uint32_t entry);

virtual FCompressedBuffer GetRawData(uint32_t entry);

Expand Down
10 changes: 5 additions & 5 deletions src/common/filesystem/source/file_7z.cpp
Expand Up @@ -179,7 +179,7 @@ class F7ZFile : public FResourceFile
F7ZFile(const char * filename, FileReader &filer, StringPool* sp);
bool Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf);
virtual ~F7ZFile();
FileData Read(int entry) override;
FileData Read(uint32_t entry) override;
FileReader GetEntryReader(uint32_t entry, int, int) override;
};

Expand Down Expand Up @@ -282,7 +282,7 @@ bool F7ZFile::Open(LumpFilterInfo *filter, FileSystemMessageFunc Printf)

FileData temp(nullptr, Entries[0].Length);

if (SZ_OK != Archive->Extract(Entries[0].Position, (char*)temp.writable()))
if (SZ_OK != Archive->Extract((UInt32)Entries[0].Position, (char*)temp.writable()))
{
Printf(FSMessageLevel::Error, "%s: unsupported 7z/LZMA file!\n", FileName);
return false;
Expand Down Expand Up @@ -314,15 +314,15 @@ F7ZFile::~F7ZFile()
//
//==========================================================================

FileData F7ZFile::Read(int entry)
FileData F7ZFile::Read(uint32_t entry)
{
FileData buffer;
if ((entry >= 0 || entry < NumLumps) && Entries[entry].Length > 0)
if (entry < NumLumps && Entries[entry].Length > 0)
{
auto p = buffer.allocate(Entries[entry].Length);
// There is no realistic way to keep multiple references to a 7z file open without massive overhead so to make this thread-safe a mutex is the only option.
std::lock_guard<FCriticalSection> lock(critsec);
SRes code = Archive->Extract(Entries[entry].Position, (char*)p);
SRes code = Archive->Extract((UInt32)Entries[entry].Position, (char*)p);
if (code != SZ_OK) buffer.clear();
}
return buffer;
Expand Down
4 changes: 2 additions & 2 deletions src/common/filesystem/source/files_decompress.cpp
Expand Up @@ -931,7 +931,7 @@ bool OpenDecompressor(FileReader& self, FileReader &parent, FileReader::Size len
{
FileData buffer(nullptr, length);
FZipExploder exploder;
if (exploder.Explode(buffer.writable(), length, *p, p->GetLength(), method - METHOD_IMPLODE_MIN) == -1)
if (exploder.Explode(buffer.writable(), (unsigned)length, *p, (unsigned)p->GetLength(), method - METHOD_IMPLODE_MIN) == -1)
{
if (exceptions)
{
Expand All @@ -947,7 +947,7 @@ bool OpenDecompressor(FileReader& self, FileReader &parent, FileReader::Size len
case METHOD_SHRINK:
{
FileData buffer(nullptr, length);
ShrinkLoop(buffer.writable(), length, *p, p->GetLength()); // this never fails.
ShrinkLoop(buffer.writable(), (unsigned)length, *p, (unsigned)p->GetLength()); // this never fails.
fr = new MemoryArrayReader(buffer);
flags &= ~(DCF_SEEKABLE | DCF_CACHED);
break;
Expand Down
4 changes: 0 additions & 4 deletions src/common/filesystem/source/filesystem.cpp
Expand Up @@ -101,10 +101,6 @@ struct FileSystem::LumpRecord

void SetFromLump(FResourceFile* file, int fileindex, int filenum, StringPool* sp, const char* name = nullptr)
{
if (fileindex == 649 && filenum == 0)
{
int a = 0;
}
resfile = file;
resindex = fileindex;
rfnum = filenum;
Expand Down
2 changes: 1 addition & 1 deletion src/common/filesystem/source/resourcefile.cpp
Expand Up @@ -709,7 +709,7 @@ FileReader FResourceFile::GetEntryReader(uint32_t entry, int readertype, int rea
return fr;
}

FileData FResourceFile::Read(int entry)
FileData FResourceFile::Read(uint32_t entry)
{
if (!(Entries[entry].Flags & RESFF_COMPRESSED) && Reader.isOpen())
{
Expand Down
10 changes: 8 additions & 2 deletions src/common/models/model.cpp
Expand Up @@ -163,7 +163,13 @@ unsigned FindModel(const char * path, const char * modelfile, bool silent)
if (!Models[i]->mFileName.CompareNoCase(fullname)) return i;
}

int len = fileSystem.FileLength(lump);
auto len = fileSystem.FileLength(lump);
if (len >= 0x80000000ll)
{
Printf(PRINT_HIGH, "LoadModel: File to large: '%s'\n", fullname.GetChars());
return -1;
}

auto lumpd = fileSystem.ReadFile(lump);
const char * buffer = lumpd.string();

Expand Down Expand Up @@ -208,7 +214,7 @@ unsigned FindModel(const char * path, const char * modelfile, bool silent)

if (model != nullptr)
{
if (!model->Load(path, lump, buffer, len))
if (!model->Load(path, lump, buffer, (int)len))
{
delete model;
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/common/scripting/interface/vmnatives.cpp
Expand Up @@ -852,7 +852,7 @@ DEFINE_ACTION_FUNCTION(_Wads, GetLumpLength)
{
PARAM_PROLOGUE;
PARAM_INT(lump);
ACTION_RETURN_INT(fileSystem.FileLength(lump));
ACTION_RETURN_INT((int)fileSystem.FileLength(lump));
}

//==========================================================================
Expand Down
3 changes: 1 addition & 2 deletions src/common/textures/formats/flattexture.cpp
Expand Up @@ -74,10 +74,9 @@ FImageSource *FlatImage_TryCreate(FileReader & file, int lumpnum)
FFlatTexture::FFlatTexture (int lumpnum)
: FImageSource(lumpnum)
{
int area;
int bits;

area = fileSystem.FileLength (lumpnum);
auto area = fileSystem.FileLength (lumpnum);

switch (area)
{
Expand Down
6 changes: 3 additions & 3 deletions src/common/textures/multipatchtexturebuilder.cpp
Expand Up @@ -285,7 +285,7 @@ void FMultipatchTextureBuilder::AddTexturesLump(const void *lumpdata, int lumpsi
}

// Check whether the amount of names reported is correct.
int lumplength = fileSystem.FileLength(patcheslump);
uint32_t lumplength = (uint32_t)fileSystem.FileLength(patcheslump);
if (numpatches > uint32_t((lumplength - 4) / 8))
{
Printf("PNAMES lump is shorter than required (%u entries reported but only %d bytes (%d entries) long\n",
Expand Down Expand Up @@ -398,12 +398,12 @@ void FMultipatchTextureBuilder::AddTexturesLumps(int lump1, int lump2, int patch
if (lump1 >= 0)
{
auto texdir = fileSystem.ReadFile(lump1);
AddTexturesLump(texdir.data(), fileSystem.FileLength(lump1), lump1, patcheslump, firstdup, true);
AddTexturesLump(texdir.data(), (int)fileSystem.FileLength(lump1), lump1, patcheslump, firstdup, true);
}
if (lump2 >= 0)
{
auto texdir = fileSystem.ReadFile(lump2);
AddTexturesLump(texdir.data(), fileSystem.FileLength(lump2), lump2, patcheslump, firstdup, false);
AddTexturesLump(texdir.data(), (int)fileSystem.FileLength(lump2), lump2, patcheslump, firstdup, false);
}
}

Expand Down

0 comments on commit 9583035

Please sign in to comment.