fix 2 more warnings for vs2013.

pull/3012/head
kimkulling 2020-03-18 16:48:32 +01:00
parent 2eb8ff7136
commit d1afd97ec2
2 changed files with 403 additions and 414 deletions

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
@ -44,8 +43,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @brief Zip File I/O implementation for #Importer
*/
#include <assimp/ZipArchiveIOSystem.h>
#include <assimp/BaseImporter.h>
#include <assimp/ZipArchiveIOSystem.h>
#include <assimp/ai_assert.h>
@ -59,6 +58,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif
namespace Assimp {
// ----------------------------------------------------------------
// Wraps an existing Assimp::IOSystem for unzip
class IOSystem2Unzip {
@ -79,12 +79,10 @@ namespace Assimp {
const char *mode_fopen = nullptr;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) {
mode_fopen = "rb";
}
else {
} else {
if (mode & ZLIB_FILEFUNC_MODE_EXISTING) {
mode_fopen = "r+b";
}
else {
} else {
if (mode & ZLIB_FILEFUNC_MODE_CREATE) {
mode_fopen = "wb";
}
@ -176,6 +174,7 @@ namespace Assimp {
class ZipFile : public IOStream {
friend class ZipFileInfo;
explicit ZipFile(size_t size);
public:
virtual ~ZipFile();
@ -193,11 +192,9 @@ namespace Assimp {
std::unique_ptr<uint8_t[]> m_Buffer;
};
// ----------------------------------------------------------------
// Info about a read-only file inside a ZIP
class ZipFileInfo
{
class ZipFileInfo {
public:
explicit ZipFileInfo(unzFile zip_handle, size_t size);
@ -209,8 +206,8 @@ namespace Assimp {
unz_file_pos_s m_ZipFilePos;
};
ZipFileInfo::ZipFileInfo(unzFile zip_handle, size_t size)
: m_Size(size) {
ZipFileInfo::ZipFileInfo(unzFile zip_handle, size_t size) :
m_Size(size) {
ai_assert(m_Size != 0);
// Workaround for MSVC 2013 - C2797
m_ZipFilePos.num_of_file = 0;
@ -229,8 +226,7 @@ namespace Assimp {
ZipFile *zip_file = new ZipFile(m_Size);
if (unzReadCurrentFile(zip_handle, zip_file->m_Buffer.get(), static_cast<unsigned int>(m_Size)) != static_cast<int>(m_Size))
{
if (unzReadCurrentFile(zip_handle, zip_file->m_Buffer.get(), static_cast<unsigned int>(m_Size)) != static_cast<int>(m_Size)) {
// Failed, release the memory
delete zip_file;
zip_file = nullptr;
@ -240,8 +236,8 @@ namespace Assimp {
return zip_file;
}
ZipFile::ZipFile(size_t size)
: m_Size(size) {
ZipFile::ZipFile(size_t size) :
m_Size(size) {
ai_assert(m_Size != 0);
m_Buffer = std::unique_ptr<uint8_t[]>(new uint8_t[m_Size]);
}
@ -256,8 +252,7 @@ namespace Assimp {
// Clip down to file size
size_t byteSize = pSize * pCount;
if ((byteSize + m_SeekPtr) > m_Size)
{
if ((byteSize + m_SeekPtr) > m_Size) {
pCount = (m_Size - m_SeekPtr) / pSize;
byteSize = pSize * pCount;
if (byteSize == 0)
@ -276,8 +271,7 @@ namespace Assimp {
}
aiReturn ZipFile::Seek(size_t pOffset, aiOrigin pOrigin) {
switch (pOrigin)
{
switch (pOrigin) {
case aiOrigin_SET: {
if (pOffset > m_Size) return aiReturn_FAILURE;
m_SeekPtr = pOffset;
@ -335,8 +329,9 @@ namespace Assimp {
ZipArchiveIOSystem::Implement::Implement(IOSystem *pIOHandler, const char *pFilename, const char *pMode) {
ai_assert(strcmp(pMode, "r") == 0);
ai_assert(pFilename != nullptr);
if (pFilename[0] == 0)
if (pFilename[0] == 0 || nullptr == pMode) {
return;
}
zlib_filefunc_def mapping = IOSystem2Unzip::get(pIOHandler);
m_ZipFileHandle = unzOpen2(pFilename, &mapping);
@ -421,8 +416,7 @@ namespace Assimp {
inline void ReplaceAll(std::string &data, const std::string &before, const std::string &after) {
size_t pos = data.find(before);
while (pos != std::string::npos)
{
while (pos != std::string::npos) {
data.replace(pos, before.size(), after);
pos = data.find(before, pos + after.size());
}
@ -430,15 +424,13 @@ namespace Assimp {
inline void ReplaceAllChar(std::string &data, const char before, const char after) {
size_t pos = data.find(before);
while (pos != std::string::npos)
{
while (pos != std::string::npos) {
data[pos] = after;
pos = data.find(before, pos + 1);
}
}
void ZipArchiveIOSystem::Implement::SimplifyFilename(std::string& filename)
{
void ZipArchiveIOSystem::Implement::SimplifyFilename(std::string &filename) {
ReplaceAllChar(filename, '\\', '/');
// Remove all . and / from the beginning of the path
@ -450,8 +442,7 @@ namespace Assimp {
static const std::string relative("/../");
const size_t relsize = relative.size() - 1;
pos = filename.find(relative);
while (pos != std::string::npos)
{
while (pos != std::string::npos) {
// Previous slash
size_t prevpos = filename.rfind('/', pos - 1);
if (prevpos == pos)
@ -463,15 +454,14 @@ namespace Assimp {
}
}
ZipArchiveIOSystem::ZipArchiveIOSystem(IOSystem* pIOHandler, const char* pFilename, const char* pMode)
: pImpl(new Implement(pIOHandler, pFilename, pMode)) {
ZipArchiveIOSystem::ZipArchiveIOSystem(IOSystem *pIOHandler, const char *pFilename, const char *pMode) :
pImpl(new Implement(pIOHandler, pFilename, pMode)) {
}
// ----------------------------------------------------------------
// The ZipArchiveIO
ZipArchiveIOSystem::ZipArchiveIOSystem(IOSystem* pIOHandler, const std::string& rFilename, const char* pMode)
: pImpl(new Implement(pIOHandler, rFilename.c_str(), pMode))
{
ZipArchiveIOSystem::ZipArchiveIOSystem(IOSystem *pIOHandler, const std::string &rFilename, const char *pMode) :
pImpl(new Implement(pIOHandler, rFilename.c_str(), pMode)) {
}
ZipArchiveIOSystem::~ZipArchiveIOSystem() {
@ -498,8 +488,7 @@ namespace Assimp {
IOStream *ZipArchiveIOSystem::Open(const char *pFilename, const char *pMode) {
ai_assert(pFilename != nullptr);
for (size_t i = 0; pMode[i] != 0; ++i)
{
for (size_t i = 0; pMode[i] != 0; ++i) {
ai_assert(pMode[i] != 'w');
if (pMode[i] == 'w')
return nullptr;
@ -534,4 +523,4 @@ namespace Assimp {
return isZipArchive(pIOHandler, rFilename.c_str());
}
}
} // namespace Assimp

View File

@ -158,7 +158,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif
#ifdef _MSC_VER
# pragma warning(disable : 4521 4714 4127)
# pragma warning(disable : 4521 4512 4714 4127)
# ifdef ASSIMP_BUILD_DLL_EXPORT
# pragma warning (disable : 4251)
# endif