diff --git a/.build_win32_amd64.txt b/.build_win32_amd64.txt index efb6541..a47cf4d 100644 --- a/.build_win32_amd64.txt +++ b/.build_win32_amd64.txt @@ -1,4 +1,4 @@ 1 success -bd69955e34daa3cc0e923a3789ff627451991441 -07 Jul 2019 19:14:36 +cb73d9df3258eaf59e4799c9e54d5f865e891734 +22 Sep 2019 13:38:56 diff --git a/CMakeLists.txt b/CMakeLists.txt index 77ff713..97a5a92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,11 @@ set(CMAKE_CXX_STANDARD 17) if(NOT WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wno-reorder -Wno-sign-compare -fpermissive -ftemplate-depth=1000 ${MEMORY_DEBUG_FLAGS}") set(CMAKE_INCLUDE_CURRENT_DIR ON) +else() + #For Windows + add_definitions(-D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING) + + add_compile_options(/wd4996) #'std::result_of_t': warning STL4014: std::result_of and std::result_of_t are deprecated in C++17. endif() if(CMAKE_PLATFORM_INCLUDE AND NOT CMAKE_PLATFORM_INCLUDE STREQUAL "") diff --git a/src/BasicChannel.cpp b/src/BasicChannel.cpp index 21dbb7c..a3c30d9 100644 --- a/src/BasicChannel.cpp +++ b/src/BasicChannel.cpp @@ -117,12 +117,12 @@ bool BasicChannel::passwordMatch(std::string password, bool hashed) { return this->properties()[property::CHANNEL_PASSWORD].as() == password; } -int BasicChannel::emptySince() { +int64_t BasicChannel::emptySince() { if (!properties().hasProperty(property::CHANNEL_LAST_LEFT)) return 0; time_point lastLeft = time_point() + milliseconds(properties()[property::CHANNEL_LAST_LEFT].as()); - return duration_cast(system_clock::now() - lastLeft).count(); + return (int64_t) duration_cast(system_clock::now() - lastLeft).count(); } void BasicChannel::setLinkedHandle(const std::weak_ptr &ptr) { diff --git a/src/BasicChannel.h b/src/BasicChannel.h index 05a9e65..299c8b6 100644 --- a/src/BasicChannel.h +++ b/src/BasicChannel.h @@ -52,7 +52,7 @@ namespace ts { bool passwordMatch(std::string password, bool hashed = false); bool defaultChannel() { return (*this->_properties)[property::CHANNEL_FLAG_DEFAULT]; } - int emptySince(); + int64_t emptySince(); inline std::chrono::system_clock::time_point createdTimestamp() { return std::chrono::system_clock::time_point() + std::chrono::milliseconds(this->properties()[property::CHANNEL_CREATED_AT].as()); diff --git a/src/Error.h b/src/Error.h index 195c7a4..40825d3 100644 --- a/src/Error.h +++ b/src/Error.h @@ -1,3 +1,5 @@ +#include + #pragma once #include @@ -256,10 +258,8 @@ namespace ts { static ErrorType VSError; static ErrorType DBEmpty; - ErrorType(const uint16_t errorId, const std::string &name, const std::string &message) : errorId(errorId), name(name), message(message) {} - - ErrorType(const ErrorType& ref) : errorId(ref.errorId), name(ref.name), message(ref.message) {} - ErrorType(ErrorType& ref) : errorId(ref.errorId), name(ref.name), message(ref.message) {} + ErrorType(const uint16_t errorId, std::string name, std::string message) : errorId(errorId), name(std::move(name)), message(std::move(message)) {} + ErrorType(const ErrorType& ref) = default; ErrorType(ErrorType&& ref) : errorId(ref.errorId), name(std::move(ref.name)), message(std::move(ref.message)) {} uint16_t errorId; diff --git a/src/License.cpp b/src/License.cpp index cbcdc8c..b585f2c 100644 --- a/src/License.cpp +++ b/src/License.cpp @@ -263,7 +263,7 @@ void LicenseChain::print() { auto key = this->generatePublicKey(); cout << "Public key: " << endl; - hexDump((char*) key.data(), key.length(), key.length(), key.length(), [](string message) { cout << message << endl; }); + hexDump((char*) key.data(), (int) key.length(), (int) key.length(), (int) key.length(), [](string message) { cout << message << endl; }); } std::string LicenseChain::exportChain() { diff --git a/src/PermissionManager.h b/src/PermissionManager.h index 26f3f21..33018c8 100644 --- a/src/PermissionManager.h +++ b/src/PermissionManager.h @@ -637,7 +637,6 @@ namespace ts { } - Permission(Permission &) = delete; Permission(const Permission &) = delete; Permission() = delete; diff --git a/src/Properties.cpp b/src/Properties.cpp index dc0d539..db79514 100644 --- a/src/Properties.cpp +++ b/src/Properties.cpp @@ -20,7 +20,7 @@ bool Properties::has(property::PropertyType type, int index) { if(!*it) continue; if(it->get()->type != type) continue; - index -= it->get()->offset; + index -= (int) it->get()->offset; if(index < 0) return false; return index < it->get()->length; } @@ -33,7 +33,7 @@ PropertyWrapper Properties::find(property::PropertyType type, int index) { if(bulk->type != type) continue; - index -= bulk->offset; + index -= (int) bulk->offset; if(index < 0) break; @@ -112,7 +112,7 @@ bool Properties::register_property_type(ts::property::PropertyType type, size_t new (&property.casted_value) any(); new (&property.value_lock) spin_lock(); new (&property.value) string(); - new (&property.description) shared_ptr(property::impl::info(type, offset + index)); + new (&property.description) shared_ptr(property::impl::info(type, (int) (offset + index))); property.flag_modified = false; property.flag_db_reference = false; diff --git a/src/Properties.h b/src/Properties.h index 6b2298f..ae87417 100644 --- a/src/Properties.h +++ b/src/Properties.h @@ -613,13 +613,19 @@ namespace ts { bool flag_modified; }; +#ifdef WIN32 + #pragma warning( push ) + #pragma warning( disable : 4200 ) +#endif struct PropertyBundle { property::PropertyType type; size_t length; size_t offset; - PropertyData properties[0]; }; +#ifdef WIN32 + #pragma warning( pop ) +#endif template struct PropertyAccess { diff --git a/src/Variable.h b/src/Variable.h index 1eb0fbe..8146640 100644 --- a/src/Variable.h +++ b/src/Variable.h @@ -127,10 +127,10 @@ DEFINE_VARIABLE_TRANSFORM(char*, VARTYPE_TEXT, std::string((const char*) in), (c DEFINE_VARIABLE_TRANSFORM(const char*, VARTYPE_TEXT, std::string((const char*) in), in.value().c_str()); DEFINE_VARIABLE_TRANSFORM(int8_t, VARTYPE_INT, std::to_string(in), std::stoi(in.value())); -DEFINE_VARIABLE_TRANSFORM(uint8_t, VARTYPE_INT, std::to_string(in), std::stoul(in.value())); +DEFINE_VARIABLE_TRANSFORM(uint8_t, VARTYPE_INT, std::to_string(in), (uint8_t) std::stoul(in.value())); DEFINE_VARIABLE_TRANSFORM(int16_t, VARTYPE_INT, std::to_string(in), std::stoi(in.value())); -DEFINE_VARIABLE_TRANSFORM(uint16_t, VARTYPE_INT, std::to_string(in), std::stoul(in.value())); +DEFINE_VARIABLE_TRANSFORM(uint16_t, VARTYPE_INT, std::to_string(in), (uint16_t) std::stoul(in.value())); DEFINE_VARIABLE_TRANSFORM(int32_t, VARTYPE_INT, std::to_string(in), std::stoi(in.value())); DEFINE_VARIABLE_TRANSFORM(uint32_t, VARTYPE_INT, std::to_string(in), std::stoul(in.value())); diff --git a/src/log/LogUtils.cpp b/src/log/LogUtils.cpp index 7ce9d00..68d3287 100644 --- a/src/log/LogUtils.cpp +++ b/src/log/LogUtils.cpp @@ -16,7 +16,7 @@ namespace fs = std::experimental::filesystem; #define ASYNC_LOG namespace logger { recursive_mutex loggerLock; - map> loggers; + map> loggers; shared_ptr logConfig; shared_ptr<::logger::TerminalSink> terminalSink; shared_ptr<::logger::CostumeFormatter> costumeFormatter; @@ -25,7 +25,7 @@ namespace logger { if(!::logger::currentConfig()) return nullptr; - int group = 0; + size_t group = 0; if(::logger::currentConfig()->vs_group_size > 0 && serverId > 0) group = serverId / ::logger::currentConfig()->vs_group_size; else group = -1; @@ -46,10 +46,15 @@ namespace logger { strvar::FunctionValue("time", (strvar::FunctionValue::FValueFNEasy) [](std::deque value) -> std::string { auto pattern = !value.empty() ? value[0] : "%Y-%m-%d_%H:%M:%S"; - tm* tm_info; auto secs = duration_cast(logConfig->timestamp.time_since_epoch()).count(); + tm* tm_info; +#ifdef WIN32 + tm _tm_info{}; + localtime_s(&_tm_info, &secs); + tm_info = &_tm_info; +#else tm_info = localtime((time_t*) &secs); - +#endif char timeBuffer[1024]; if(strftime(timeBuffer, 1024, pattern.c_str(), tm_info) == 0) { return string("string is longer than the buffer"); diff --git a/src/misc/base64.cpp b/src/misc/base64.cpp index 5d80e2b..fd7483c 100644 --- a/src/misc/base64.cpp +++ b/src/misc/base64.cpp @@ -4,7 +4,7 @@ std::string base64::decode(const char* input, size_t size) { auto out = new unsigned char[size]; - if(base64_strict_decode((unsigned char*) input, size, out, (unsigned long*) &size) != CRYPT_OK){ + if(base64_strict_decode((unsigned char*) input, (unsigned long) size, out, (unsigned long*) &size) != CRYPT_OK){ std::cerr << "Invalid base 64 string '" << input << "'" << std::endl; return ""; } diff --git a/src/misc/base64.h b/src/misc/base64.h index 241883d..9697b31 100644 --- a/src/misc/base64.h +++ b/src/misc/base64.h @@ -17,7 +17,7 @@ namespace base64 { * @param input The input string to Base64-encode * @return A Base64-encoded version of the encoded string */ - inline std::string encode(const std::string& input) { return encode(input.c_str(), input.size()); } + inline std::string encode(const std::string& input) { return encode(input.c_str(), (unsigned long) input.size()); } /** @@ -48,4 +48,4 @@ namespace base64 { } } inline std::string base64_encode(const char* input, const unsigned long inputSize) { return base64::encode(input, inputSize); } -inline std::string base64_encode(const std::string& input) { return base64::encode(input.c_str(), input.size()); } \ No newline at end of file +inline std::string base64_encode(const std::string& input) { return base64::encode(input.c_str(), (unsigned long) input.size()); } \ No newline at end of file diff --git a/src/misc/digest.cpp b/src/misc/digest.cpp index 82721e3..206b113 100644 --- a/src/misc/digest.cpp +++ b/src/misc/digest.cpp @@ -2,12 +2,12 @@ #ifdef NO_OPEN_SSL #include - #define DECLARE_DIGEST(name, digestLength) \ - void digest::tomcrypt::name(const char* input, size_t length, uint8_t* result) { \ + #define DECLARE_DIGEST(name, digestLength) \ + void digest::tomcrypt::name(const char* input, size_t length, uint8_t* result) { \ hash_state hash{}; \ \ name ##_init(&hash); \ - name ##_process(&hash, (uint8_t*) input, length); \ + name ##_process(&hash, (uint8_t*) input, (unsigned long) length); \ name ##_done(&hash, result); \ } diff --git a/src/protocol/Packet.cpp b/src/protocol/Packet.cpp index f0b9502..0cfbf52 100644 --- a/src/protocol/Packet.cpp +++ b/src/protocol/Packet.cpp @@ -26,7 +26,6 @@ namespace ts { delete this->data; } - PacketTypeInfo::PacketTypeInfo(PacketTypeInfo &red) : data(red.data) { } PacketTypeInfo::PacketTypeInfo(const PacketTypeInfo &red) : data(red.data) { } std::map PacketTypeInfo::types; @@ -65,13 +64,13 @@ namespace ts { } BasicPacket::BasicPacket(size_t header_length, size_t data_length) { - this->_header_length = header_length; + this->_header_length = (uint8_t) header_length; this->_buffer = pipes::buffer(MAC_SIZE + this->_header_length + data_length); memset(this->_buffer.data_ptr(), 0, this->_buffer.length()); } BasicPacket::BasicPacket(size_t header_length, const pipes::buffer &buffer) { - this->_header_length = header_length; + this->_header_length = (uint8_t) header_length; this->_buffer = buffer; } diff --git a/src/protocol/Packet.h b/src/protocol/Packet.h index 29473ca..e51e0cf 100644 --- a/src/protocol/Packet.h +++ b/src/protocol/Packet.h @@ -64,7 +64,6 @@ namespace ts { inline bool fragmentable() { return *this == PacketTypeInfo::Command || *this == PacketTypeInfo::CommandLow; } inline bool compressable() { return *this == PacketTypeInfo::Command || *this == PacketTypeInfo::CommandLow; } - PacketTypeInfo(PacketTypeInfo&); PacketTypeInfo(const PacketTypeInfo&); PacketTypeInfo(PacketTypeInfo&& remote) : data(remote.data) {} @@ -88,7 +87,7 @@ namespace ts { PacketIdManager() : data(new PacketIdManagerData){} ~PacketIdManager() = default; PacketIdManager(const PacketIdManager& ref) : data(ref.data) {} - PacketIdManager(PacketIdManager& ref) : data(ref.data) {} + PacketIdManager(PacketIdManager&& ref) : data(std::move(ref.data)) {} uint16_t nextPacketId(const PacketTypeInfo &type){ return static_cast(data->packetCounter[type.type()]++ & 0xFFFF); diff --git a/src/protocol/buffers.cpp b/src/protocol/buffers.cpp index 1cdd606..ae4fe6e 100644 --- a/src/protocol/buffers.cpp +++ b/src/protocol/buffers.cpp @@ -5,7 +5,9 @@ using namespace ts; using namespace ts::protocol; using namespace ts::buffer; -#pragma GCC optimize ("O3") +#ifndef WIN32 + #pragma GCC optimize ("O3") +#endif meminfo buffer::buffer_memory() { size_t bytes_buffer = 0; diff --git a/src/protocol/buffers_allocator_c.cpp b/src/protocol/buffers_allocator_c.cpp index 4e29d31..20cb740 100644 --- a/src/protocol/buffers_allocator_c.cpp +++ b/src/protocol/buffers_allocator_c.cpp @@ -5,7 +5,9 @@ using namespace ts; using namespace ts::protocol; using namespace ts::buffer; -#pragma GCC optimize ("O3") +#ifndef WIN32 + #pragma GCC optimize ("O3") +#endif buffer_t buffer::allocate_buffer(size::value size) { return pipes::buffer{buffer::size::byte_length(size)}; diff --git a/src/query/Command.cpp b/src/query/Command.cpp index ee7bc38..2308414 100644 --- a/src/query/Command.cpp +++ b/src/query/Command.cpp @@ -111,7 +111,9 @@ namespace ts { key = data.substr(current_index, index_assign - current_index); try { value = query::unescape(string(data.substr(index_assign + 1, end_index - index_assign - 1)), true); - } catch(std::invalid_argument& ex) { + } catch(const std::invalid_argument& ex) { + (void) ex; + /* invalid character at index X */ if(!drop_non_utf8) throw; diff --git a/src/query/Command.h b/src/query/Command.h index 9921d07..5b1fe7d 100644 --- a/src/query/Command.h +++ b/src/query/Command.h @@ -179,12 +179,12 @@ operator type(){ \ Json::Value buildJson() const; #endif - const ParameterBulk& operator[](int index) const { + const ParameterBulk& operator[](size_t index) const { if(bulks.size() <= index) throw std::invalid_argument("got out of length"); return bulks[index]; } - ParameterBulk& operator[](int index){ + ParameterBulk& operator[](size_t index){ while(bulks.size() <= index) bulks.push_back(ParameterBulk{}); return bulks[index]; } diff --git a/src/query/command2.cpp b/src/query/command2.cpp index c1e8aba..6e3b93c 100644 --- a/src/query/command2.cpp +++ b/src/query/command2.cpp @@ -143,7 +143,9 @@ command command::parse(const std::string_view &data, bool expect_type, bool drop key = data.substr(current_index, index_assign - current_index); try { value = query::unescape(string(data.substr(index_assign + 1, end_index - index_assign - 1)), true); - } catch(std::invalid_argument& ex) { + } catch(const std::invalid_argument& ex) { + (void) ex; + /* invalid character at index X */ if(!drop_non_utf8) throw;