Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xrCore] Several Level 3 warnings eliminated #1623

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Common/Compiler.inl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#endif

#elif defined(_MSC_VER)
// XXX: Disables MSVC warnings on unsafe C library functions. Should be removed later.
#define _CRT_SECURE_NO_WARNINGS
#include <intrin.h> // for __debugbreak

#define NO_INLINE __declspec(noinline)
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/Animation/Motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void COMotion::DeleteKey(float t) const
envs[ctRotationB]->DeleteKey(t);
}

int COMotion::KeyCount() const { return envs[ctPositionX]->keys.size(); }
size_t COMotion::KeyCount() const { return envs[ctPositionX]->keys.size(); }

void COMotion::FindNearestKey(float t, float& mn, float& mx, float eps) const
{
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/Animation/Motion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class XRCORE_API COMotion final : public CCustomMotion
void CreateKey(float t, const Fvector& P, const Fvector& R) const;
void DeleteKey(float t) const;
void NormalizeKeys();
int KeyCount() const;
size_t KeyCount() const;
CEnvelope* Envelope(EChannelType et = ctPositionX) { return envs[et]; }
BOOL ScaleKeys(float from_time, float to_time, float scale_factor) const;
BOOL NormalizeKeys(float from_time, float to_time, float speed);
Expand Down
8 changes: 4 additions & 4 deletions src/xrCore/Animation/SkeletonMotions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class XRCORE_API CPartDef
CPartDef() : Name(0){};

[[nodiscard]]
u32 mem_usage() const { return sizeof(*this) + bones.size() * sizeof(u32) + sizeof(Name); }
u64 mem_usage() const { return sizeof(*this) + bones.size() * sizeof(bones[0]) + sizeof(Name); }
};
class XRCORE_API CPartition
{
Expand All @@ -188,7 +188,7 @@ class XRCORE_API CPartition
IC CPartDef& operator[](u16 id) { return P[id]; }
IC const CPartDef& part(u16 id) const { return P[id]; }
[[nodiscard]] u16 part_id(const shared_str& name) const;
[[nodiscard]] u32 mem_usage() const { return P[0].mem_usage() * MAX_PARTS; }
[[nodiscard]] u64 mem_usage() const { return P[0].mem_usage() * MAX_PARTS; }
void load(IKinematics* V, pcstr model_name);

[[nodiscard]] u8 count() const
Expand Down Expand Up @@ -217,9 +217,9 @@ struct XRCORE_API motions_value
BOOL load(pcstr N, IReader* data, vecBones* bones);
MotionVec* bone_motions(shared_str bone_name);

u32 mem_usage()
u64 mem_usage()
{
u32 sz = sizeof(*this) + m_motion_map.size() * 6 + m_partition.mem_usage();
u64 sz = sizeof(*this) + m_motion_map.size() * 6 + m_partition.mem_usage();
for (auto it = m_mdefs.begin(); it != m_mdefs.end(); ++it)
sz += it->mem_usage();
for (auto bm_it = m_motions.begin(); bm_it != m_motions.end(); ++bm_it)
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/Animation/interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ float evalEnvelope(CEnvelope* env, float time)
return env->keys[0]->value;

// find the first and last keys
int sz = env->keys.size();
size_t sz = env->keys.size();
skey = env->keys[0];
ekey = env->keys[sz - 1];
skey_n = env->keys[1];
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/Compression/rt_compressor9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
thread_local HEAP_ALLOC(rtc9_wrkmem, LZO1X_999_MEM_COMPRESS);

static u8* _LZO_Dictionary = nullptr;
static u32 _LZO_DictionarySize = 0;
static lzo_uint _LZO_DictionarySize = 0;

//------------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions src/xrCore/Crypto/trivial_encryptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void trivial_encryptor::initialize(key_flag what)
m_alphabet_back[m_alphabet[i]] = (type)i;
}

void trivial_encryptor::encode(pcvoid source, const u32& source_size, pvoid destination, key_flag what /*= key_flag::worldwide*/)
void trivial_encryptor::encode(pcvoid source, const size_t& source_size, pvoid destination, key_flag what /*= key_flag::worldwide*/)
{
if (what != m_current_key)
{
Expand All @@ -75,7 +75,7 @@ void trivial_encryptor::encode(pcvoid source, const u32& source_size, pvoid dest
*J = m_alphabet[*I] ^ type(temp.random(alphabet_size) & 0xff);
}

void trivial_encryptor::decode(pcvoid source, const u32& source_size, pvoid destination, key_flag what /*= key_flag::worldwide*/)
void trivial_encryptor::decode(pcvoid source, const size_t& source_size, pvoid destination, key_flag what /*= key_flag::worldwide*/)
{
if (what != m_current_key)
{
Expand Down
4 changes: 2 additions & 2 deletions src/xrCore/Crypto/trivial_encryptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class XRCORE_API trivial_encryptor
public:
trivial_encryptor();

void encode(pcvoid source, const u32& source_size, pvoid destination, key_flag what = key_flag::worldwide);
void decode(pcvoid source, const u32& source_size, pvoid destination, key_flag what = key_flag::worldwide);
void encode(pcvoid source, const size_t& source_size, pvoid destination, key_flag what = key_flag::worldwide);
void decode(pcvoid source, const size_t& source_size, pvoid destination, key_flag what = key_flag::worldwide);
};

extern XRCORE_API trivial_encryptor g_trivial_encryptor;
4 changes: 2 additions & 2 deletions src/xrCore/LocatorAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ const CLocatorAPI::file* CLocatorAPI::Register(
IReader* open_chunk(void* ptr, u32 ID, pcstr archiveName, size_t archiveSize, bool shouldDecrypt = false)
{
u32 dwType = INVALID_SET_FILE_POINTER;
size_t dwSize = 0;
u32 dwSize = 0;
DWORD read_byte;
u32 pt = SetFilePointer(ptr, 0, nullptr, FILE_BEGIN);
VERIFY(pt != INVALID_SET_FILE_POINTER);
Expand Down Expand Up @@ -1388,7 +1388,7 @@ void CLocatorAPI::file_from_archive(IReader*& R, pcstr fname, const file& desc)
end = A.size;
const size_t sz = end - start;
#if defined(XR_PLATFORM_WINDOWS)
u8* ptr = (u8*)MapViewOfFile(A.hSrcMap, FILE_MAP_READ, 0, start, sz);
u8* ptr = (u8*)MapViewOfFile(A.hSrcMap, FILE_MAP_READ, 0, static_cast<DWORD>(start), sz);
VERIFY3(ptr, "cannot create file mapping on file", fname);
#elif defined(XR_PLATFORM_LINUX) || defined(XR_PLATFORM_BSD) || defined(XR_PLATFORM_APPLE)
u8* ptr = (u8*)::mmap(NULL, sz, PROT_READ, MAP_SHARED, A.hSrcFile, start);
Expand Down
8 changes: 4 additions & 4 deletions src/xrCore/XML/XMLDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ XML_NODE XMLDocument::NavigateToNode(pcstr path, const size_t node_index) const
XML_NODE XMLDocument::NavigateToNodeWithAttribute(pcstr tag_name, pcstr attrib_name, pcstr attrib_value) const
{
CONST_XML_NODE root = GetLocalRoot() ? GetLocalRoot() : GetRoot();
int tabsCount = GetNodesNum(root, tag_name);
size_t tabsCount = GetNodesNum(root, tag_name);

for (int i = 0; i < tabsCount; ++i)
for (size_t i = 0; i < tabsCount; ++i)
{
pcstr result = ReadAttrib(root, tag_name, i, attrib_name, "");
if (result && xr_strcmp(result, attrib_value) == 0)
Expand Down Expand Up @@ -523,9 +523,9 @@ pcstr XMLDocument::CheckUniqueAttrib(CONST_XML_NODE start_node, pcstr tag_name,
{
m_AttribValues.clear();

int tags_num = GetNodesNum(start_node, tag_name);
size_t tags_num = GetNodesNum(start_node, tag_name);

for (int i = 0; i < tags_num; i++)
for (size_t i = 0; i < tags_num; i++)
{
pcstr attrib = ReadAttrib(start_node, tag_name, i, attrib_name, nullptr);

Expand Down
6 changes: 3 additions & 3 deletions src/xrCore/_std_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ constexpr u32 operator""_hash(char const* p, size_t size) { return strhash({ p,

XRCORE_API char* timestamp(string64& dest);

extern XRCORE_API u32 crc32(const void* P, u32 len);
extern XRCORE_API u32 crc32(const void* P, u32 len, u32 starting_crc);
extern XRCORE_API u32 path_crc32(const char* path, u32 len); // ignores '/' and '\'
extern XRCORE_API u32 crc32(const void* P, size_t len);
extern XRCORE_API u32 crc32(const void* P, size_t len, u32 starting_crc);
extern XRCORE_API u32 path_crc32(const char* path, size_t len); // ignores '/' and '\'

#endif // _STD_EXT_internal
6 changes: 3 additions & 3 deletions src/xrCore/crc32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ constexpr std::array<u32, 256> generate_crc32_lookup_table() noexcept
// Lookup table array
static constexpr auto crc32_table = generate_crc32_lookup_table();

u32 crc32(const void* P, u32 len)
u32 crc32(const void* P, size_t len)
{
// Pass a text string to this function and it will return the CRC.

Expand All @@ -68,7 +68,7 @@ u32 crc32(const void* P, u32 len)
return ulCRC ^ 0xffffffff;
}

u32 crc32(const void* P, u32 len, u32 starting_crc)
u32 crc32(const void* P, size_t len, u32 starting_crc)
{
u32 ulCRC = 0xffffffff ^ starting_crc;
u8* buffer = (u8*)P;
Expand All @@ -79,7 +79,7 @@ u32 crc32(const void* P, u32 len, u32 starting_crc)
return ulCRC ^ 0xffffffff;
}

u32 path_crc32(const char* path, u32 len)
u32 path_crc32(const char* path, size_t len)
{
u32 ulCRC = 0xffffffff;
u8* buffer = (u8*)path;
Expand Down
22 changes: 11 additions & 11 deletions src/xrCore/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void Log(pcstr s)
{
int i, j;

const u32 length = xr_strlen(s);
const size_t length = xr_strlen(s);
pstr split = static_cast<pstr>(xr_alloca((length + 1) * sizeof(char)));
for (i = 0, j = 0; s[i] != 0; i++)
{
Expand Down Expand Up @@ -125,15 +125,15 @@ void Log(pcstr msg, pcstr dop)
return;
}

const u32 buffer_size = (xr_strlen(msg) + 1 + xr_strlen(dop) + 1) * sizeof(char);
const size_t buffer_size = (xr_strlen(msg) + 1 + xr_strlen(dop) + 1) * sizeof(char);
pstr buf = static_cast<pstr>(xr_alloca(buffer_size));
strconcat(buffer_size, buf, msg, " ", dop);
Log(buf);
}

void Log(pcstr msg, int dop)
{
const u32 buffer_size = (xr_strlen(msg) + 1 + 11 + 1) * sizeof(char);
const size_t buffer_size = (xr_strlen(msg) + 1 + 11 + 1) * sizeof(char);
pstr buf = static_cast<pstr>(xr_alloca(buffer_size));

xr_sprintf(buf, buffer_size, "%s %i", msg, dop);
Expand All @@ -142,7 +142,7 @@ void Log(pcstr msg, int dop)

void Log(pcstr msg, unsigned int dop)
{
const u32 buffer_size = (xr_strlen(msg) + 1 + 10 + 1) * sizeof(char);
const size_t buffer_size = (xr_strlen(msg) + 1 + 10 + 1) * sizeof(char);
pstr buf = static_cast<pstr>(xr_alloca(buffer_size));

xr_sprintf(buf, buffer_size, "%s %u", msg, dop);
Expand All @@ -151,7 +151,7 @@ void Log(pcstr msg, unsigned int dop)

void Log(pcstr msg, long dop)
{
const u32 buffer_size = (xr_strlen(msg) + 1 + 64 + 1) * sizeof(char);
const size_t buffer_size = (xr_strlen(msg) + 1 + 64 + 1) * sizeof(char);
pstr buf = static_cast<pstr>(xr_alloca(buffer_size));

xr_sprintf(buf, buffer_size, "%s %li", msg, dop);
Expand All @@ -160,7 +160,7 @@ void Log(pcstr msg, long dop)

void Log(pcstr msg, unsigned long dop)
{
const u32 buffer_size = (xr_strlen(msg) + 1 + 64 + 1) * sizeof(char);
const size_t buffer_size = (xr_strlen(msg) + 1 + 64 + 1) * sizeof(char);
pstr buf = static_cast<pstr>(xr_alloca(buffer_size));

xr_sprintf(buf, buffer_size, "%s %lu", msg, dop);
Expand All @@ -169,7 +169,7 @@ void Log(pcstr msg, unsigned long dop)

void Log(pcstr msg, long long dop)
{
const u32 buffer_size = (xr_strlen(msg) + 1 + 64 + 1) * sizeof(char);
const size_t buffer_size = (xr_strlen(msg) + 1 + 64 + 1) * sizeof(char);
pstr buf = static_cast<pstr>(xr_alloca(buffer_size));

xr_sprintf(buf, buffer_size, "%s %lli", msg, dop);
Expand All @@ -178,7 +178,7 @@ void Log(pcstr msg, long long dop)

void Log(pcstr msg, unsigned long long dop)
{
const u32 buffer_size = (xr_strlen(msg) + 1 + 64 + 1) * sizeof(char);
const size_t buffer_size = (xr_strlen(msg) + 1 + 64 + 1) * sizeof(char);
pstr buf = static_cast<pstr>(xr_alloca(buffer_size));

xr_sprintf(buf, buffer_size, "%s %llu", msg, dop);
Expand All @@ -189,7 +189,7 @@ void Log(pcstr msg, float dop)
{
// actually, float string representation should be no more, than 40 characters,
// but we will count with slight overhead
const u32 buffer_size = (xr_strlen(msg) + 1 + 64 + 1) * sizeof(char);
const size_t buffer_size = (xr_strlen(msg) + 1 + 64 + 1) * sizeof(char);
pstr buf = static_cast<pstr>(xr_alloca(buffer_size));

xr_sprintf(buf, buffer_size, "%s %f", msg, dop);
Expand All @@ -198,7 +198,7 @@ void Log(pcstr msg, float dop)

void Log(pcstr msg, const Fvector& dop)
{
const u32 buffer_size = (xr_strlen(msg) + 2 + 3 * (64 + 1) + 1) * sizeof(char);
const size_t buffer_size = (xr_strlen(msg) + 2 + 3 * (64 + 1) + 1) * sizeof(char);
pstr buf = static_cast<pstr>(xr_alloca(buffer_size));

xr_sprintf(buf, buffer_size, "%s (%f,%f,%f)", msg, VPUSH(dop));
Expand All @@ -207,7 +207,7 @@ void Log(pcstr msg, const Fvector& dop)

void Log(pcstr msg, const Fmatrix& dop)
{
const u32 buffer_size = (xr_strlen(msg) + 2 + 4 * (4 * (64 + 1) + 1) + 1) * sizeof(char);
const size_t buffer_size = (xr_strlen(msg) + 2 + 4 * (4 * (64 + 1) + 1) + 1) * sizeof(char);
pstr buf = static_cast<pstr>(xr_alloca(buffer_size));

xr_sprintf(buf, buffer_size, "%s:\n%f,%f,%f,%f\n%f,%f,%f,%f\n%f,%f,%f,%f\n%f,%f,%f,%f\n", msg, dop.i.x, dop.i.y,
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/stream_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void CStreamReader::map(const size_t& new_offset)
m_current_window_size = end_offset - start_offset;
#if defined(XR_PLATFORM_WINDOWS)
m_current_map_view_of_file =
static_cast<u8*>(MapViewOfFile(m_file_mapping_handle, FILE_MAP_READ, 0, start_offset, m_current_window_size));
static_cast<u8*>(MapViewOfFile(m_file_mapping_handle, FILE_MAP_READ, 0, static_cast<DWORD>(start_offset), m_current_window_size));
#elif defined(XR_PLATFORM_LINUX) || defined(XR_PLATFORM_BSD) || defined(XR_PLATFORM_APPLE)
m_current_map_view_of_file =
static_cast<u8*>(::mmap(NULL, m_current_window_size, PROT_READ, MAP_SHARED, m_file_mapping_handle, start_offset));
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/stream_reader_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ IC intptr_t CStreamReader::elapsed() const
}

IC const size_t& CStreamReader::length() const { return m_file_size; }
IC void CStreamReader::seek(const int& offset) { advance(offset - tell()); }
IC void CStreamReader::seek(const int& offset) { advance(offset - static_cast<int>(tell())); }
IC size_t CStreamReader::tell() const
{
VERIFY(m_current_pointer >= m_start_pointer);
Expand Down
36 changes: 20 additions & 16 deletions src/xrCore/string_concatenations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ namespace detail
{
namespace strconcat_error
{
void process(u32 const index, u32 const count, pcstr* strings)
void process(size_t const index, size_t const count, pcstr* strings)
{
u32 const max_string_size = 1024;
constexpr size_t max_string_size = 1024;
// XXX: Why stack allocation?
pstr temp = (pstr)xr_alloca((count * (max_string_size + 4) + 1) * sizeof(**strings));
pstr k = temp;
*k++ = '[';
for (u32 i = 0; i < count; ++i)
for (size_t i = 0; i < count; ++i)
{
for (pcstr j = strings[i], e = j + max_string_size; *j && j < e; ++k, ++j)
*k = *j;
Expand All @@ -42,8 +43,8 @@ void process(u32 const index, u32 const count, pcstr* strings)
DEBUG_INFO, make_string("buffer overflow: cannot concatenate strings(%d):\r\n%s", index, temp).c_str());
}

template <u32 count>
static inline void process(pstr& i, pcstr e, u32 const index, pcstr (&strings)[count])
template <size_t count>
static inline void process(pstr& i, pcstr e, size_t const index, pcstr (&strings)[count])
{
VERIFY(i <= e);
VERIFY(index < count);
Expand Down Expand Up @@ -91,25 +92,28 @@ void check_stack_overflow(u32 stack_increment)

void string_tupples::error_process() const
{
constexpr auto npos = std::numeric_limits<size_t>::max();

pcstr strings[MAX_ITEM_COUNT];
size_t part_size = 0;
size_t overrun_string_index = npos;

u32 part_size = 0;
u32 overrun_string_index = (u32)-1;
for (u32 i = 0; i < m_count; ++i)
for (size_t i = 0; i < m_count; ++i)
{
strings[i] = m_strings[i].first;
const auto [str, size] = m_strings[i];

strings[i] = str;
part_size += size;

if (overrun_string_index == (u32)-1)
if (part_size > MAX_CONCAT_RESULT_SIZE)
{
part_size += m_strings[i].second;
if (part_size > MAX_CONCAT_RESULT_SIZE)
{
overrun_string_index = i;
}
overrun_string_index = i;
// No need to continue, index has been found
break;
}
}
VERIFY(overrun_string_index != -1);

VERIFY(overrun_string_index != npos);
strconcat_error::process(overrun_string_index, m_count, strings);
}

Expand Down
8 changes: 4 additions & 4 deletions src/xrCore/string_concatenations_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class XRCORE_API string_tupples
}

private:
static const u32 MAX_CONCAT_RESULT_SIZE = static_cast<u32>(512 * 1024);
static const u32 MAX_ITEM_COUNT = static_cast<u32>(6);
static const size_t MAX_CONCAT_RESULT_SIZE = static_cast<size_t>(512 * 1024);
static const size_t MAX_ITEM_COUNT = static_cast<size_t>(6);

template <u32 index>
template <size_t index>
struct helper
{
static size_t get_length(pcstr string) { return string ? xr_strlen(string) : 0; }
Expand All @@ -85,7 +85,7 @@ class XRCORE_API string_tupples
using StringPair = std::pair<pcstr, size_t>;

StringPair m_strings[MAX_ITEM_COUNT];
u32 m_count;
size_t m_count;
};

void XRCORE_API check_stack_overflow(u32 stack_increment);
Expand Down
Loading