2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-06-27 23:01:55 +00:00

Fix more gcc compilation issues

This commit is contained in:
Jan
2021-03-03 09:12:27 -08:00
parent a15fd17dfe
commit 1a45cf2107
84 changed files with 786 additions and 713 deletions

View File

@ -1,6 +1,9 @@
#include "IwiLoader.h"
#include "Image/IwiTypes.h"
#include <cassert>
#include <type_traits>
#include "Image/IwiTypes.h"
IwiLoader::IwiLoader(MemoryManager* memoryManager)
{
@ -56,8 +59,8 @@ Texture* IwiLoader::LoadIwi8(std::istream& stream) const
{
iwi8::IwiHeader header{};
stream.read(reinterpret_cast<char*>(&header), sizeof header);
if (stream.gcount() != sizeof header)
stream.read(reinterpret_cast<char*>(&header), sizeof(header));
if (stream.gcount() != sizeof(header))
return nullptr;
const auto* format = GetFormat8(header.format);
@ -95,7 +98,7 @@ Texture* IwiLoader::LoadIwi8(std::istream& stream) const
texture->Allocate();
auto currentFileSize = sizeof iwi8::IwiHeader + sizeof IwiVersion;
auto currentFileSize = sizeof(iwi8::IwiHeader) + sizeof(IwiVersion);
const auto mipMapCount = hasMipMaps ? texture->GetMipMapCount() : 1;
for (auto currentMipLevel = mipMapCount - 1; currentMipLevel >= 0; currentMipLevel--)
@ -103,7 +106,7 @@ Texture* IwiLoader::LoadIwi8(std::istream& stream) const
const auto sizeOfMipLevel = texture->GetSizeOfMipLevel(currentMipLevel) * texture->GetFaceCount();
currentFileSize += sizeOfMipLevel;
if (currentMipLevel < static_cast<int>(_countof(iwi8::IwiHeader::fileSizeForPicmip))
if (currentMipLevel < static_cast<int>(std::extent<decltype(iwi8::IwiHeader::fileSizeForPicmip)>::value)
&& currentFileSize != header.fileSizeForPicmip[currentMipLevel])
{
printf("Iwi has invalid file size for picmip %i\n", currentMipLevel);
@ -173,8 +176,8 @@ Texture* IwiLoader::LoadIwi27(std::istream& stream) const
{
iwi27::IwiHeader header{};
stream.read(reinterpret_cast<char*>(&header), sizeof header);
if (stream.gcount() != sizeof header)
stream.read(reinterpret_cast<char*>(&header), sizeof(header));
if (stream.gcount() != sizeof(header))
return nullptr;
const auto* format = GetFormat27(header.format);
@ -202,7 +205,7 @@ Texture* IwiLoader::LoadIwi27(std::istream& stream) const
texture->Allocate();
auto currentFileSize = sizeof iwi27::IwiHeader + sizeof IwiVersion;
auto currentFileSize = sizeof(iwi27::IwiHeader) + sizeof(IwiVersion);
const auto mipMapCount = hasMipMaps ? texture->GetMipMapCount() : 1;
for (auto currentMipLevel = mipMapCount - 1; currentMipLevel >= 0; currentMipLevel--)
@ -210,7 +213,7 @@ Texture* IwiLoader::LoadIwi27(std::istream& stream) const
const auto sizeOfMipLevel = texture->GetSizeOfMipLevel(currentMipLevel) * texture->GetFaceCount();
currentFileSize += sizeOfMipLevel;
if (currentMipLevel < static_cast<int>(_countof(iwi27::IwiHeader::fileSizeForPicmip))
if (currentMipLevel < static_cast<int>(std::extent<decltype(iwi27::IwiHeader::fileSizeForPicmip)>::value)
&& currentFileSize != header.fileSizeForPicmip[currentMipLevel])
{
printf("Iwi has invalid file size for picmip %i\n", currentMipLevel);
@ -236,8 +239,8 @@ Texture* IwiLoader::LoadIwi(std::istream& stream)
{
IwiVersion iwiVersion{};
stream.read(reinterpret_cast<char*>(&iwiVersion), sizeof iwiVersion);
if (stream.gcount() != sizeof iwiVersion)
stream.read(reinterpret_cast<char*>(&iwiVersion), sizeof(iwiVersion));
if (stream.gcount() != sizeof(iwiVersion))
return nullptr;
if (iwiVersion.tag[0] != 'I'

View File

@ -10,7 +10,7 @@ const std::string& IPakLoadException::DetailedMessage() const
return m_message;
}
char const* IPakLoadException::what() const
char const* IPakLoadException::what() const noexcept
{
return "There was an error when trying to load an ipak file.";
}

View File

@ -10,5 +10,5 @@ public:
explicit IPakLoadException(std::string message);
const std::string& DetailedMessage() const;
char const* what() const override;
char const* what() const noexcept override;
};

View File

@ -1,6 +1,7 @@
#include "IPakEntryReadStream.h"
#include <cassert>
#include <cstring>
#include <minilzo.h>
@ -72,8 +73,8 @@ bool IPakEntryReadStream::SetChunkBufferWindow(const int64_t startPos, size_t ch
if (m_buffer_start_pos != startPos)
{
const auto moveEnd = endPos < m_buffer_end_pos ? endPos : m_buffer_end_pos;
memmove_s(m_chunk_buffer, IPAK_CHUNK_SIZE * IPAK_CHUNK_COUNT_PER_READ, &m_chunk_buffer[startPos - m_buffer_start_pos],
static_cast<size_t>(moveEnd - startPos));
assert(IPAK_CHUNK_SIZE * IPAK_CHUNK_COUNT_PER_READ >= static_cast<size_t>(moveEnd - startPos));
memmove(m_chunk_buffer, &m_chunk_buffer[startPos - m_buffer_start_pos], static_cast<size_t>(moveEnd - startPos));
m_buffer_start_pos = startPos;
}
@ -93,10 +94,8 @@ bool IPakEntryReadStream::SetChunkBufferWindow(const int64_t startPos, size_t ch
if (endPos > m_buffer_start_pos && endPos <= m_buffer_end_pos)
{
memmove_s(&m_chunk_buffer[m_buffer_start_pos - startPos],
IPAK_CHUNK_SIZE * IPAK_CHUNK_COUNT_PER_READ - static_cast<size_t>(m_buffer_start_pos - startPos),
m_chunk_buffer,
static_cast<size_t>(endPos - m_buffer_start_pos));
assert(IPAK_CHUNK_SIZE * IPAK_CHUNK_COUNT_PER_READ - static_cast<size_t>(m_buffer_start_pos - startPos) >= static_cast<size_t>(endPos - m_buffer_start_pos));
memmove(&m_chunk_buffer[m_buffer_start_pos - startPos], m_chunk_buffer, static_cast<size_t>(endPos - m_buffer_start_pos));
const auto readChunkCount = ReadChunks(m_chunk_buffer,
startPos,
@ -151,8 +150,7 @@ bool IPakEntryReadStream::AdjustChunkBufferWindowForBlockHeader(IPakDataBlockHea
commandsSize += blockHeader->_commands[commandIndex].size;
}
const size_t requiredChunkCount = AlignForward<size_t>(
blockOffsetInChunk + sizeof IPakDataBlockHeader + commandsSize, IPAK_CHUNK_SIZE) / IPAK_CHUNK_SIZE;
const size_t requiredChunkCount = AlignForward<size_t>(blockOffsetInChunk + sizeof(IPakDataBlockHeader) + commandsSize, IPAK_CHUNK_SIZE) / IPAK_CHUNK_SIZE;
const size_t amountOfReadChunks = static_cast<size_t>(m_buffer_end_pos - m_buffer_start_pos) / IPAK_CHUNK_SIZE;
@ -177,7 +175,7 @@ bool IPakEntryReadStream::NextBlock()
if (m_pos >= m_end_pos)
return false;
m_pos = AlignForward<int64_t>(m_pos, sizeof IPakDataBlockHeader);
m_pos = AlignForward<int64_t>(m_pos, sizeof(IPakDataBlockHeader));
const auto chunkStartPos = AlignBackwards<int64_t>(m_pos, IPAK_CHUNK_SIZE);
const auto blockOffsetInChunk = static_cast<size_t>(m_pos - chunkStartPos);
@ -200,7 +198,7 @@ bool IPakEntryReadStream::NextBlock()
if (!AdjustChunkBufferWindowForBlockHeader(m_current_block, blockOffsetInChunk))
return false;
m_pos += sizeof IPakDataBlockHeader;
m_pos += sizeof(IPakDataBlockHeader);
m_next_command = 0;
return true;
@ -212,7 +210,7 @@ bool IPakEntryReadStream::ProcessCommand(const size_t commandSize, const int com
{
if (compressed == 1)
{
lzo_uint outputSize = sizeof m_decompress_buffer;
lzo_uint outputSize = sizeof(m_decompress_buffer);
const auto result = lzo1x_decompress_safe(&m_chunk_buffer[m_pos - m_buffer_start_pos], commandSize,
m_decompress_buffer, &outputSize, nullptr);
@ -336,8 +334,8 @@ std::streamsize IPakEntryReadStream::xsgetn(char* ptr, const std::streamsize cou
if (sizeToRead > 0)
{
memcpy_s(&destBuffer[countRead], static_cast<rsize_t>(count - countRead),
&m_current_command_buffer[m_current_command_offset], static_cast<rsize_t>(sizeToRead));
assert(static_cast<size_t>(count - countRead) >= static_cast<size_t>(sizeToRead));
memcpy(&destBuffer[countRead], &m_current_command_buffer[m_current_command_offset], static_cast<size_t>(sizeToRead));
countRead += sizeToRead;
m_current_command_offset += sizeToRead;
m_file_offset += sizeToRead;