fix warnings

This commit is contained in:
xensik
2022-04-12 19:13:10 +02:00
parent a7cd82508c
commit 8c59bf78ee
123 changed files with 4465 additions and 4240 deletions

View File

@ -5,37 +5,24 @@
#pragma once
// Warnings
#ifdef _WIN32
#pragma warning(disable:4005)
#pragma warning(disable:4018)
#pragma warning(disable:4065)
#pragma warning(disable:4127)
#pragma warning(disable:4244)
#pragma warning(disable:4267)
#pragma warning(disable:4389)
#define _CRT_SECURE_NO_WARNINGS
#endif
// C/C++
#include <regex>
#include <string>
#include <vector>
#include <memory>
#include <cstdio>
#include <algorithm>
#include <filesystem>
#include <functional>
#include <stdexcept>
#include <map>
#include <stack>
#include <array>
#include <iostream>
#include <sstream>
#include <filesystem>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <vector>
// Ext
using namespace std::literals;
#include "xsk/utils.hpp"

View File

@ -15,7 +15,7 @@ auto asset::serialize() -> std::vector<std::uint8_t>
data.resize(name.size() + compressedLen + bytecodeLen + 13);
std::memset(data.data(), 0, data.size());
auto pos = 0u;
std::size_t pos = 0;
std::memcpy(&data[pos], name.data(), name.size() + 1);
pos += name.size() + 1;
@ -39,7 +39,7 @@ auto asset::serialize() -> std::vector<std::uint8_t>
void asset::deserialize(std::vector<std::uint8_t> data)
{
auto pos = 0u;
std::size_t pos = 0;
name = std::string(reinterpret_cast<const char*>(data.data()));
pos += name.size() + 1;

View File

@ -87,7 +87,7 @@ void block::merge(const std::vector<block*>& childs)
{
auto child = childs[childidx];
child->local_vars_public_count = this->local_vars.size();
child->local_vars_public_count = static_cast<std::uint32_t>(this->local_vars.size());
for (std::size_t i = 0; i < this->local_vars.size(); i++ )
{
auto& name = this->local_vars.at(i).name;
@ -147,7 +147,7 @@ auto block::find_variable(std::size_t start, const std::string& name) -> std::in
for (std::size_t i = start; i < local_vars.size(); ++i )
{
if (local_vars.at(i).name == name)
return i;
return static_cast<std::int32_t>(i);
}
return -1;
}
@ -159,14 +159,14 @@ void block::transfer_decompiler(const block::ptr& child)
child->local_vars.push_back(this->local_vars.at(i));
}
child->local_vars_public_count = this->local_vars.size();
child->local_vars_public_count = static_cast<std::uint32_t>(this->local_vars.size());
}
void block::append_decompiler(const block::ptr& child, bool all)
{
auto total = all ? child->local_vars.size() : child->local_vars_public_count;
for (std::uint32_t i = this->local_vars.size(); i < total; i++ )
for (auto i = this->local_vars.size(); i < total; i++ )
{
this->local_vars.push_back(child->local_vars.at(i));
}

View File

@ -5,20 +5,17 @@
#pragma once
// Utility
#include "utils/file.hpp"
#include "utils/string.hpp"
#include "utils/byte_buffer.hpp"
#include "utils/compression.hpp"
// GSC Types
#include "gsc/location.hpp"
#include "gsc/types.hpp"
#include "gsc/asset.hpp"
#include "gsc/block.hpp"
#include "gsc/nodetree.hpp"
// GSC Interfaces
#include "gsc/interfaces/exception.hpp"
#include "gsc/interfaces/assembler.hpp"
#include "gsc/interfaces/disassembler.hpp"
@ -26,13 +23,11 @@
#include "gsc/interfaces/decompiler.hpp"
#include "gsc/interfaces/context.hpp"
// ARC Types
#include "arc/location.hpp"
#include "arc/types.hpp"
#include "arc/block.hpp"
#include "arc/nodetree.hpp"
// ARC Interfaces
#include "arc/interfaces/exception.hpp"
#include "arc/interfaces/assembler.hpp"
#include "arc/interfaces/disassembler.hpp"

View File

@ -10,16 +10,16 @@ namespace xsk::utils
byte_buffer::byte_buffer()
{
data_.resize(0x1000000);
std::fill(data_.begin(), data_.end(), 0);
size_ = data_.size();
data_.resize(0x100000);
std::fill(data_.begin(), data_.end(), '\0');
size_ = static_cast<std::uint32_t>(data_.size());
pos_ = 0;
}
byte_buffer::byte_buffer(std::size_t size)
byte_buffer::byte_buffer(std::uint32_t size)
{
data_.resize(size);
std::fill(data_.begin(), data_.end(), 0);
std::fill(data_.begin(), data_.end(), '\0');
size_ = size;
pos_ = 0;
}
@ -27,56 +27,61 @@ byte_buffer::byte_buffer(std::size_t size)
byte_buffer::byte_buffer(const std::vector<std::uint8_t>& data)
{
data_ = data;
size_ = data.size();
size_ = static_cast<std::uint32_t>(data_.size());
pos_ = 0;
}
byte_buffer::~byte_buffer()
{
data_.clear();
size_ = 0;
pos_ = 0;
}
void byte_buffer::clear()
{
std::fill(data_.begin(), data_.end(), 0);
std::fill(data_.begin(), data_.end(), '\0');
}
auto byte_buffer::is_avail() -> bool
{
if (pos_ < data_.size()) return true;
return false;
return (pos_ < size_) ? true : false;
}
void byte_buffer::seek(std::size_t pos)
void byte_buffer::seek(std::uint32_t count)
{
pos_ += pos;
pos_ += count;
}
void byte_buffer::seek_neg(std::size_t pos)
void byte_buffer::seek_neg(std::uint32_t count)
{
pos_ -= pos;
pos_ -= count;
}
void byte_buffer::write_string(const std::string& data)
{
strcpy(reinterpret_cast<char*>(data_.data() + pos_), data.data());
pos_ += data.size();
if (pos_ + data.size() > size_) return;
std::memcpy(reinterpret_cast<void*>(data_.data() + pos_), data.data(), data.size());
pos_ += static_cast<std::uint32_t>(data.size());
}
void byte_buffer::write_c_string(const std::string& data)
{
strcpy(reinterpret_cast<char*>(data_.data() + pos_), data.data());
pos_ += data.size() + 1;
if (pos_ + data.size() >= size_) return;
std::memcpy(reinterpret_cast<void*>(data_.data() + pos_), data.data(), data.size());
pos_ += static_cast<std::uint32_t>(data.size() + 1);
}
auto byte_buffer::read_c_string() -> std::string
{
auto ret = std::string(reinterpret_cast<const char*>(data_.data() + pos_));
pos_ += ret.size() + 1;
pos_ += static_cast<std::uint32_t>(ret.size() + 1);
return ret;
}
auto byte_buffer::print_bytes(std::size_t pos, std::size_t count) -> std::string
auto byte_buffer::print_bytes(std::uint32_t pos, std::uint32_t count) -> std::string
{
std::string data {};
@ -88,12 +93,12 @@ auto byte_buffer::print_bytes(std::size_t pos, std::size_t count) -> std::string
return data;
}
auto byte_buffer::pos() -> std::size_t
auto byte_buffer::pos() -> std::uint32_t
{
return pos_;
}
void byte_buffer::pos(std::size_t pos)
void byte_buffer::pos(std::uint32_t pos)
{
if (pos >= 0 && pos <= size_)
{
@ -101,7 +106,7 @@ void byte_buffer::pos(std::size_t pos)
}
}
auto byte_buffer::align(std::size_t size) -> std::size_t
auto byte_buffer::align(std::uint32_t size) -> std::uint32_t
{
auto pos = pos_;

View File

@ -15,18 +15,20 @@ public:
private:
std::vector<std::uint8_t> data_;
std::size_t size_;
std::size_t pos_;
std::uint32_t size_;
std::uint32_t pos_;
public:
byte_buffer();
byte_buffer(std::size_t size);
byte_buffer(std::uint32_t size);
byte_buffer(const std::vector<std::uint8_t>& data);
~byte_buffer();
template <typename T>
auto read() -> T
{
if (pos_ + sizeof(T) > size_) return T{};
auto ret = *reinterpret_cast<T*>(data_.data() + pos_);
pos_ += sizeof(T);
return ret;
@ -35,6 +37,8 @@ public:
template <typename T>
void write(T data)
{
if (pos_ + sizeof(T) > size_) return;
T* mem = reinterpret_cast<T*>(data_.data() + pos_);
std::memcpy(mem, &data, sizeof(T));
pos_ += sizeof(T);
@ -43,6 +47,8 @@ public:
template <typename T>
auto read_endian() -> T
{
if (pos_ + sizeof(T) > size_) return T{};
std::array<std::uint8_t, sizeof(T)> mem;
for (auto i = 0; i < sizeof(T); i++)
@ -58,6 +64,8 @@ public:
template <typename T>
void write_endian(T data)
{
if (pos_ + sizeof(T) > size_) return;
auto* mem = data_.data() + pos_;
for (auto i = 0; i < sizeof(T); i++)
@ -70,15 +78,15 @@ public:
void clear();
auto is_avail() -> bool;
void seek(std::size_t pos);
void seek_neg(std::size_t pos);
void seek(std::uint32_t count);
void seek_neg(std::uint32_t count);
void write_string(const std::string& data);
void write_c_string(const std::string& data);
auto read_c_string() -> std::string;
auto print_bytes(std::size_t pos, std::size_t count) -> std::string;
auto pos() -> std::size_t;
void pos(std::size_t pos);
auto align(std::size_t size) -> std::size_t;
auto print_bytes(std::uint32_t pos, std::uint32_t count) -> std::string;
auto pos() -> std::uint32_t;
void pos(std::uint32_t pos);
auto align(std::uint32_t size) -> std::uint32_t;
auto buffer() -> std::vector<std::uint8_t>&;
};

View File

@ -30,7 +30,7 @@ auto zlib::decompress(const std::vector<std::uint8_t>& data, std::uint32_t lengt
std::vector<std::uint8_t> output;
output.resize(length);
auto result = uncompress(output.data(), (uLongf*)&length, (Bytef*)data.data(), data.size());
auto result = uncompress(reinterpret_cast<Bytef*>(output.data()), reinterpret_cast<uLong*>(&length), reinterpret_cast<const Bytef*>(data.data()), static_cast<uLong>(data.size()));
if (result != Z_OK) return {};

View File

@ -48,7 +48,7 @@ auto string::to_lower(const std::string& input) -> std::string
for (std::size_t i = 0; i < data.size(); i++)
{
data[i] = std::tolower(input[i]);
data[i] = static_cast<char>(std::tolower(static_cast<unsigned char>(input[i])));
}
return data;
@ -271,7 +271,7 @@ auto string::float_string(float value) -> std::string
while (i < str.size())
p_exp.push_back(str[i++]);
auto offset = std::stoi(p_exp);
std::size_t offset = std::stoi(p_exp);
if ((flags & exp_neg))
offset -= p_int.size();
@ -303,7 +303,7 @@ auto string::float_string(float value) -> std::string
while (i < str.size())
p_exp.push_back(str[i++]);
auto offset = std::stoi(p_exp);
std::size_t offset = std::stoi(p_exp);
offset -= (flags & exp_neg) ? p_int.size() : p_dec.size();