Skip to content

Commit

Permalink
Fix warnings in MpqWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
obligaron authored and AJenbo committed Dec 21, 2023
1 parent 63f4f38 commit 780015b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions Source/mpq/mpq_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ MpqWriter::MpqWriter(const char *path)
const char *mode = "wb";
if (exists) {
mode = "r+b";
if (!GetFileSize(path, &size_)) {
std::uintmax_t fileSize;
if (!GetFileSize(path, &fileSize)) {
error = R"(GetFileSize failed: "{}")";
LogError(error, path, std::strerror(errno));
goto on_error;
}
size_ = static_cast<uint32_t>(fileSize);
LogVerbose("GetFileSize(\"{}\") = {}", path, size_);
}
if (!stream_.Open(path, mode)) {
Expand Down Expand Up @@ -360,7 +362,7 @@ MpqBlockEntry *MpqWriter::AddFile(std::string_view filename, MpqBlockEntry *bloc
return block;
}

bool MpqWriter::WriteFileContents(const std::byte *fileData, size_t fileSize, MpqBlockEntry *block)
bool MpqWriter::WriteFileContents(const std::byte *fileData, uint32_t fileSize, MpqBlockEntry *block)
{
const uint32_t numSectors = (fileSize + (BlockSize - 1)) / BlockSize;
const uint32_t offsetTableByteSize = sizeof(uint32_t) * (numSectors + 1);
Expand Down Expand Up @@ -442,7 +444,7 @@ bool MpqWriter::WriteHeader()
memset(&fhdr, 0, sizeof(fhdr));
fhdr.signature = MpqFileHeader::DiabloSignature;
fhdr.headerSize = MpqFileHeader::DiabloSize;
fhdr.fileSize = static_cast<uint32_t>(size_);
fhdr.fileSize = size_;
fhdr.version = 0;
fhdr.blockSizeFactor = BlockSizeFactor;
fhdr.hashEntriesOffset = MpqHashEntryOffset;
Expand Down Expand Up @@ -501,7 +503,7 @@ bool MpqWriter::WriteFile(std::string_view filename, const std::byte *data, size

RemoveHashEntry(filename);
blockEntry = AddFile(filename, nullptr, 0);
if (!WriteFileContents(data, size, blockEntry)) {
if (!WriteFileContents(data, static_cast<uint32_t>(size), blockEntry)) {
RemoveHashEntry(filename);
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/mpq/mpq_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MpqWriter {

bool ReadMPQHeader(MpqFileHeader *hdr);
MpqBlockEntry *AddFile(std::string_view filename, MpqBlockEntry *block, uint32_t blockIndex);
bool WriteFileContents(const std::byte *fileData, size_t fileSize, MpqBlockEntry *block);
bool WriteFileContents(const std::byte *fileData, uint32_t fileSize, MpqBlockEntry *block);

// Returns an unused entry in the block entry table.
MpqBlockEntry *NewBlock(uint32_t *blockIndex = nullptr);
Expand All @@ -57,7 +57,7 @@ class MpqWriter {

LoggedFStream stream_;
std::string name_;
std::uintmax_t size_ {};
uint32_t size_ {};
std::unique_ptr<MpqHashEntry[]> hashTable_;
std::unique_ptr<MpqBlockEntry[]> blockTable_;

Expand Down

0 comments on commit 780015b

Please sign in to comment.