citra-emu
/
citra
Archived
1
0
Fork 0

Merge pull request #6602 from SachinVin/wall

Chore: enable `-Werror` on GCC and clang
This commit is contained in:
SachinVin 2023-06-18 22:37:39 +05:30 committed by GitHub
commit 35d1b67fd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 124 additions and 114 deletions

View File

@ -3,6 +3,8 @@
# Suppress warnings from external libraries # Suppress warnings from external libraries
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/W0) add_compile_options(/W0)
else()
add_compile_options(-Wno-error)
endif() endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules)
@ -112,6 +114,8 @@ add_library(nihstro-headers INTERFACE)
target_include_directories(nihstro-headers INTERFACE ./nihstro/include) target_include_directories(nihstro-headers INTERFACE ./nihstro/include)
if (MSVC) if (MSVC)
target_compile_options(nihstro-headers INTERFACE /W0) target_compile_options(nihstro-headers INTERFACE /W0)
else()
target_compile_options(nihstro-headers INTERFACE -Wno-error)
endif() endif()
# Open Source Archives # Open Source Archives
@ -195,6 +199,11 @@ if (ENABLE_WEB_SERVICE)
add_library(cpp-jwt INTERFACE) add_library(cpp-jwt INTERFACE)
target_include_directories(cpp-jwt INTERFACE ./cpp-jwt/include) target_include_directories(cpp-jwt INTERFACE ./cpp-jwt/include)
target_compile_definitions(cpp-jwt INTERFACE CPP_JWT_USE_VENDORED_NLOHMANN_JSON) target_compile_definitions(cpp-jwt INTERFACE CPP_JWT_USE_VENDORED_NLOHMANN_JSON)
if (MSVC)
target_compile_options(cpp-jwt INTERFACE /W0)
else()
target_compile_options(cpp-jwt INTERFACE -Wno-error)
endif()
endif() endif()
# lodepng # lodepng

View File

@ -102,6 +102,10 @@ else()
-Wno-attributes -Wno-attributes
) )
if (CITRA_WARNINGS_AS_ERRORS)
add_compile_options(-Werror)
endif()
if (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL Clang) if (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL Clang)
add_compile_options("-stdlib=libc++") add_compile_options("-stdlib=libc++")
endif() endif()

View File

@ -56,35 +56,6 @@ std::condition_variable running_cv;
} // Anonymous namespace } // Anonymous namespace
static bool DisplayAlertMessage(const char* caption, const char* text, bool yes_no) {
JNIEnv* env = IDCache::GetEnvForThread();
// Execute the Java method.
jboolean result = env->CallStaticBooleanMethod(
IDCache::GetNativeLibraryClass(), IDCache::GetDisplayAlertMsg(), ToJString(env, caption),
ToJString(env, text), yes_no ? JNI_TRUE : JNI_FALSE);
return result != JNI_FALSE;
}
static std::string DisplayAlertPrompt(const char* caption, const char* text, int buttonConfig) {
JNIEnv* env = IDCache::GetEnvForThread();
jstring value = reinterpret_cast<jstring>(env->CallStaticObjectMethod(
IDCache::GetNativeLibraryClass(), IDCache::GetDisplayAlertPrompt(), ToJString(env, caption),
ToJString(env, text), buttonConfig));
return GetJString(env, value);
}
static int AlertPromptButton() {
JNIEnv* env = IDCache::GetEnvForThread();
// Execute the Java method.
return static_cast<int>(env->CallStaticIntMethod(IDCache::GetNativeLibraryClass(),
IDCache::GetAlertPromptButton()));
}
static jobject ToJavaCoreError(Core::System::ResultStatus result) { static jobject ToJavaCoreError(Core::System::ResultStatus result) {
static const std::map<Core::System::ResultStatus, const char*> CoreErrorNameMap{ static const std::map<Core::System::ResultStatus, const char*> CoreErrorNameMap{
{Core::System::ResultStatus::ErrorSystemFiles, "ErrorSystemFiles"}, {Core::System::ResultStatus::ErrorSystemFiles, "ErrorSystemFiles"},

View File

@ -31,7 +31,7 @@ av_hwframe_ctx_init_func av_hwframe_ctx_init;
av_hwframe_get_buffer_func av_hwframe_get_buffer; av_hwframe_get_buffer_func av_hwframe_get_buffer;
av_hwframe_transfer_data_func av_hwframe_transfer_data; av_hwframe_transfer_data_func av_hwframe_transfer_data;
av_int_list_length_for_size_func av_int_list_length_for_size; av_int_list_length_for_size_func av_int_list_length_for_size;
#if LIBAVCODEC_VERSION_MAJOR >= 59 #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(56, 53, 100) // lavu 56.53.100
av_opt_child_class_iterate_func av_opt_child_class_iterate; av_opt_child_class_iterate_func av_opt_child_class_iterate;
#else #else
av_opt_child_class_next_func av_opt_child_class_next; av_opt_child_class_next_func av_opt_child_class_next;
@ -166,7 +166,7 @@ static bool LoadAVUtil() {
LOAD_SYMBOL(avutil, av_hwframe_get_buffer); LOAD_SYMBOL(avutil, av_hwframe_get_buffer);
LOAD_SYMBOL(avutil, av_hwframe_transfer_data); LOAD_SYMBOL(avutil, av_hwframe_transfer_data);
LOAD_SYMBOL(avutil, av_int_list_length_for_size); LOAD_SYMBOL(avutil, av_int_list_length_for_size);
#if LIBAVCODEC_VERSION_MAJOR >= 59 #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(56, 53, 100) // lavu 56.53.100
LOAD_SYMBOL(avutil, av_opt_child_class_iterate); LOAD_SYMBOL(avutil, av_opt_child_class_iterate);
#else #else
LOAD_SYMBOL(avutil, av_opt_child_class_next); LOAD_SYMBOL(avutil, av_opt_child_class_next);

View File

@ -47,7 +47,7 @@ typedef int (*av_hwframe_ctx_init_func)(AVBufferRef*);
typedef int (*av_hwframe_get_buffer_func)(AVBufferRef*, AVFrame*, int); typedef int (*av_hwframe_get_buffer_func)(AVBufferRef*, AVFrame*, int);
typedef int (*av_hwframe_transfer_data_func)(AVFrame*, const AVFrame*, int); typedef int (*av_hwframe_transfer_data_func)(AVFrame*, const AVFrame*, int);
typedef unsigned (*av_int_list_length_for_size_func)(unsigned, const void*, uint64_t); typedef unsigned (*av_int_list_length_for_size_func)(unsigned, const void*, uint64_t);
#if LIBAVCODEC_VERSION_MAJOR >= 59 #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(56, 53, 100) // lavu 56.53.100
typedef const AVClass* (*av_opt_child_class_iterate_func)(const AVClass*, void**); typedef const AVClass* (*av_opt_child_class_iterate_func)(const AVClass*, void**);
#else #else
typedef const AVClass* (*av_opt_child_class_next_func)(const AVClass*, const AVClass*); typedef const AVClass* (*av_opt_child_class_next_func)(const AVClass*, const AVClass*);
@ -85,7 +85,7 @@ extern av_hwframe_ctx_init_func av_hwframe_ctx_init;
extern av_hwframe_get_buffer_func av_hwframe_get_buffer; extern av_hwframe_get_buffer_func av_hwframe_get_buffer;
extern av_hwframe_transfer_data_func av_hwframe_transfer_data; extern av_hwframe_transfer_data_func av_hwframe_transfer_data;
extern av_int_list_length_for_size_func av_int_list_length_for_size; extern av_int_list_length_for_size_func av_int_list_length_for_size;
#if LIBAVCODEC_VERSION_MAJOR >= 59 #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(56, 53, 100) // lavu 56.53.100
extern av_opt_child_class_iterate_func av_opt_child_class_iterate; extern av_opt_child_class_iterate_func av_opt_child_class_iterate;
#else #else
extern av_opt_child_class_next_func av_opt_child_class_next; extern av_opt_child_class_next_func av_opt_child_class_next;

View File

@ -102,12 +102,11 @@ static void StripTailDirSlashes(std::string& fname) {
} }
bool Exists(const std::string& filename) { bool Exists(const std::string& filename) {
struct stat file_info;
std::string copy(filename); std::string copy(filename);
StripTailDirSlashes(copy); StripTailDirSlashes(copy);
#ifdef _WIN32 #ifdef _WIN32
struct stat file_info;
// Windows needs a slash to identify a driver root // Windows needs a slash to identify a driver root
if (copy.size() != 0 && copy.back() == ':') if (copy.size() != 0 && copy.back() == ':')
copy += DIR_SEP_CHR; copy += DIR_SEP_CHR;
@ -116,6 +115,7 @@ bool Exists(const std::string& filename) {
#elif ANDROID #elif ANDROID
int result = AndroidStorage::FileExists(filename) ? 0 : -1; int result = AndroidStorage::FileExists(filename) ? 0 : -1;
#else #else
struct stat file_info;
int result = stat(copy.c_str(), &file_info); int result = stat(copy.c_str(), &file_info);
#endif #endif
@ -699,7 +699,7 @@ static const std::string& GetHomeDirectory() {
* @return The directory path * @return The directory path
* @sa http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html * @sa http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
*/ */
static const std::string GetUserDirectory(const std::string& envvar) { [[maybe_unused]] static const std::string GetUserDirectory(const std::string& envvar) {
const char* directory = getenv(envvar.c_str()); const char* directory = getenv(envvar.c_str());
std::string user_dir; std::string user_dir;

View File

@ -16,19 +16,33 @@
// Call directly after the command or use the error num. // Call directly after the command or use the error num.
// This function might change the error code. // This function might change the error code.
std::string GetLastErrorMsg() { std::string GetLastErrorMsg() {
constexpr std::size_t buff_size = 255;
char err_str[buff_size];
std::size_t msg_len;
#ifdef _WIN32 #ifdef _WIN32
msg_len = LPSTR err_str;
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr); DWORD res = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPSTR>(&err_str), 1, nullptr);
if (!res) {
return "(FormatMessageA failed to format error)";
}
std::string ret(err_str);
LocalFree(err_str);
return ret;
#else
char err_str[255];
#if (defined(__GLIBC__) || __ANDROID_API__ >= 23) && \
(_GNU_SOURCE || (_POSIX_C_SOURCE < 200112L && _XOPEN_SOURCE < 600))
// Thread safe (GNU-specific)
const char* str = strerror_r(errno, err_str, sizeof(err_str));
return std::string(str);
#else #else
// Thread safe (XSI-compliant) // Thread safe (XSI-compliant)
strerror_r(errno, err_str, buff_size); int second_err = strerror_r(errno, err_str, sizeof(err_str));
msg_len = strnlen(err_str, buff_size); if (second_err != 0) {
#endif return "(strerror_r failed to format error)";
}
return std::string(err_str, msg_len); return std::string(err_str);
#endif // GLIBC etc.
#endif // _WIN32
} }

View File

@ -170,7 +170,7 @@ static std::wstring CPToUTF16(u32 code_page, const std::string& input) {
MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0);
if (size == 0) { if (size == 0) {
return L""; return {};
} }
std::wstring output(size, L'\0'); std::wstring output(size, L'\0');

View File

@ -110,7 +110,7 @@ void ARMul_State::Reset() {
Reg[13] = 0x10000000; Reg[13] = 0x10000000;
Reg[15] = 0; Reg[15] = 0;
Cpsr = static_cast<u32>(INTBITS) | SVC32MODE; Cpsr = static_cast<u32>(INTBITS) | static_cast<u32>(SVC32MODE);
Mode = SVC32MODE; Mode = SVC32MODE;
Bank = SVCBANK; Bank = SVCBANK;

View File

@ -52,7 +52,7 @@ void CheatEngine::AddCheat(const std::shared_ptr<CheatBase>& cheat) {
void CheatEngine::RemoveCheat(std::size_t index) { void CheatEngine::RemoveCheat(std::size_t index) {
std::unique_lock<std::shared_mutex> lock(cheats_list_mutex); std::unique_lock<std::shared_mutex> lock(cheats_list_mutex);
if (index < 0 || index >= static_cast<int>(cheats_list.size())) { if (index < 0 || index >= cheats_list.size()) {
LOG_ERROR(Core_Cheats, "Invalid index {}", index); LOG_ERROR(Core_Cheats, "Invalid index {}", index);
return; return;
} }
@ -61,7 +61,7 @@ void CheatEngine::RemoveCheat(std::size_t index) {
void CheatEngine::UpdateCheat(std::size_t index, const std::shared_ptr<CheatBase>& new_cheat) { void CheatEngine::UpdateCheat(std::size_t index, const std::shared_ptr<CheatBase>& new_cheat) {
std::unique_lock<std::shared_mutex> lock(cheats_list_mutex); std::unique_lock<std::shared_mutex> lock(cheats_list_mutex);
if (index < 0 || index >= static_cast<int>(cheats_list.size())) { if (index < 0 || index >= cheats_list.size()) {
LOG_ERROR(Core_Cheats, "Invalid index {}", index); LOG_ERROR(Core_Cheats, "Invalid index {}", index);
return; return;
} }

View File

@ -59,21 +59,25 @@ void FFmpegStream::Flush() {
SendFrame(nullptr); SendFrame(nullptr);
} }
void FFmpegStream::WritePacket(AVPacket& packet) { void FFmpegStream::WritePacket(AVPacket* packet) {
FFmpeg::av_packet_rescale_ts(&packet, codec_context->time_base, stream->time_base); FFmpeg::av_packet_rescale_ts(packet, codec_context->time_base, stream->time_base);
packet.stream_index = stream->index; packet->stream_index = stream->index;
{ {
std::lock_guard lock{*format_context_mutex}; std::lock_guard lock{*format_context_mutex};
FFmpeg::av_interleaved_write_frame(format_context, &packet); FFmpeg::av_interleaved_write_frame(format_context, packet);
} }
} }
void FFmpegStream::SendFrame(AVFrame* frame) { void FFmpegStream::SendFrame(AVFrame* frame) {
// Initialize packet // Initialize packet
AVPacket packet; AVPacket* packet = FFmpeg::av_packet_alloc();
FFmpeg::av_init_packet(&packet); if (!packet) {
packet.data = nullptr; LOG_ERROR(Render, "Frame dropped: av_packet_alloc failed");
packet.size = 0; }
SCOPE_EXIT({ FFmpeg::av_packet_free(&packet); });
packet->data = nullptr;
packet->size = 0;
// Encode frame // Encode frame
if (FFmpeg::avcodec_send_frame(codec_context.get(), frame) < 0) { if (FFmpeg::avcodec_send_frame(codec_context.get(), frame) < 0) {
@ -82,7 +86,7 @@ void FFmpegStream::SendFrame(AVFrame* frame) {
} }
int error = 1; int error = 1;
while (error >= 0) { while (error >= 0) {
error = FFmpeg::avcodec_receive_packet(codec_context.get(), &packet); error = FFmpeg::avcodec_receive_packet(codec_context.get(), packet);
if (error == AVERROR(EAGAIN) || error == AVERROR_EOF) if (error == AVERROR(EAGAIN) || error == AVERROR_EOF)
return; return;
if (error < 0) { if (error < 0) {
@ -485,7 +489,7 @@ bool FFmpegAudioStream::Init(FFmpegMuxer& muxer) {
} }
codec_context->time_base.num = 1; codec_context->time_base.num = 1;
codec_context->time_base.den = codec_context->sample_rate; codec_context->time_base.den = codec_context->sample_rate;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100) #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100) // lavc 59.24.100
codec_context->ch_layout = AV_CHANNEL_LAYOUT_STEREO; codec_context->ch_layout = AV_CHANNEL_LAYOUT_STEREO;
#else #else
codec_context->channel_layout = AV_CH_LAYOUT_STEREO; codec_context->channel_layout = AV_CH_LAYOUT_STEREO;
@ -527,7 +531,7 @@ bool FFmpegAudioStream::Init(FFmpegMuxer& muxer) {
audio_frame->format = codec_context->sample_fmt; audio_frame->format = codec_context->sample_fmt;
audio_frame->sample_rate = codec_context->sample_rate; audio_frame->sample_rate = codec_context->sample_rate;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100) #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100) // lavc 59.24.100
auto num_channels = codec_context->ch_layout.nb_channels; auto num_channels = codec_context->ch_layout.nb_channels;
audio_frame->ch_layout = codec_context->ch_layout; audio_frame->ch_layout = codec_context->ch_layout;
SwrContext* context = nullptr; SwrContext* context = nullptr;
@ -1003,7 +1007,7 @@ void GetOptionList(std::vector<OptionInfo>& out, const AVClass* av_class, bool s
} }
const AVClass* child_class = nullptr; const AVClass* child_class = nullptr;
#if LIBAVCODEC_VERSION_MAJOR >= 59 #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(56, 53, 100) // lavu 56.53.100
void* iter = nullptr; void* iter = nullptr;
while ((child_class = FFmpeg::av_opt_child_class_iterate(av_class, &iter))) { while ((child_class = FFmpeg::av_opt_child_class_iterate(av_class, &iter))) {
#else #else

View File

@ -37,7 +37,7 @@ public:
protected: protected:
~FFmpegStream(); ~FFmpegStream();
void WritePacket(AVPacket& packet); void WritePacket(AVPacket* packet);
void SendFrame(AVFrame* frame); void SendFrame(AVFrame* frame);
struct AVCodecContextDeleter { struct AVCodecContextDeleter {
@ -52,6 +52,12 @@ protected:
} }
}; };
struct AVPacketDeleter {
void operator()(AVPacket* packet) const {
av_packet_free(&packet);
}
};
AVFormatContext* format_context{}; AVFormatContext* format_context{};
std::mutex* format_context_mutex{}; std::mutex* format_context_mutex{};
std::unique_ptr<AVCodecContext, AVCodecContextDeleter> codec_context{}; std::unique_ptr<AVCodecContext, AVCodecContextDeleter> codec_context{};

View File

@ -31,7 +31,7 @@ enum class LowPathType : u32 {
}; };
union Mode { union Mode {
u32 hex; u32 hex = 0;
BitField<0, 1, u32> read_flag; BitField<0, 1, u32> read_flag;
BitField<1, 1, u32> write_flag; BitField<1, 1, u32> write_flag;
BitField<2, 1, u32> create_flag; BitField<2, 1, u32> create_flag;

View File

@ -90,7 +90,7 @@ union CoreVersion {
major.Assign(major_ver); major.Assign(major_ver);
} }
u32 raw; u32 raw = 0;
BitField<8, 8, u32> revision; BitField<8, 8, u32> revision;
BitField<16, 8, u32> minor; BitField<16, 8, u32> minor;
BitField<24, 8, u32> major; BitField<24, 8, u32> major;

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <algorithm> #include <algorithm>
#include <climits>
#include <list> #include <list>
#include <vector> #include <vector>
#include <boost/serialization/string.hpp> #include <boost/serialization/string.hpp>
@ -288,7 +289,7 @@ void ThreadManager::DebugThreadQueue() {
for (auto& t : thread_list) { for (auto& t : thread_list) {
u32 priority = ready_queue.contains(t.get()); u32 priority = ready_queue.contains(t.get());
if (priority != -1) { if (priority != UINT_MAX) {
LOG_DEBUG(Kernel, "0x{:02X} {}", priority, t->GetObjectId()); LOG_DEBUG(Kernel, "0x{:02X} {}", priority, t->GetObjectId());
} }
} }

View File

@ -904,7 +904,7 @@ void Module::SetSystemSetupNeeded(bool setup_needed) {
} }
bool Module::IsSystemSetupNeeded() { bool Module::IsSystemSetupNeeded() {
u32 block; u32 block{};
GetConfigInfoBlock(SystemSetupRequiredBlockID, sizeof(block), 0xC, &block); GetConfigInfoBlock(SystemSetupRequiredBlockID, sizeof(block), 0xC, &block);
return (block & 0xFFFF) == 0; return (block & 0xFFFF) == 0;
} }

View File

@ -204,12 +204,11 @@ void ExtraHID::HandleReadCalibrationDataRequest(const std::vector<u8>& request_b
return; return;
} }
std::vector<u8> response(5); std::vector<u8> response(5 + size);
response[0] = static_cast<u8>(ResponseID::ReadCalibrationData); response[0] = static_cast<u8>(ResponseID::ReadCalibrationData);
std::memcpy(&response[1], &request.offset, sizeof(request.offset)); std::memcpy(&response[1], &request.offset, sizeof(request.offset));
std::memcpy(&response[3], &request.size, sizeof(request.size)); std::memcpy(&response[3], &request.size, sizeof(request.size));
response.insert(response.end(), calibration_data.begin() + offset, std::memcpy(&response[5], calibration_data.data() + offset, size);
calibration_data.begin() + offset + size);
Send(response); Send(response);
} }

View File

@ -303,6 +303,7 @@ std::vector<u8> GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node
std::memcpy(eapol_buffer.data(), &eapol_start, sizeof(eapol_start)); std::memcpy(eapol_buffer.data(), &eapol_start, sizeof(eapol_start));
std::vector<u8> buffer = GenerateLLCHeader(EtherType::EAPoL); std::vector<u8> buffer = GenerateLLCHeader(EtherType::EAPoL);
buffer.reserve(buffer.size() + sizeof(EAPoLStartPacket));
buffer.insert(buffer.end(), eapol_buffer.begin(), eapol_buffer.end()); buffer.insert(buffer.end(), eapol_buffer.begin(), eapol_buffer.end());
return buffer; return buffer;
} }
@ -366,6 +367,7 @@ std::vector<u8> GenerateEAPoLLogoffFrame(const MacAddress& mac_address, u16 netw
std::memcpy(eapol_buffer.data(), &eapol_logoff, sizeof(eapol_logoff)); std::memcpy(eapol_buffer.data(), &eapol_logoff, sizeof(eapol_logoff));
std::vector<u8> buffer = GenerateLLCHeader(EtherType::EAPoL); std::vector<u8> buffer = GenerateLLCHeader(EtherType::EAPoL);
buffer.reserve(buffer.size() + sizeof(EAPoLStartPacket));
buffer.insert(buffer.end(), eapol_buffer.begin(), eapol_buffer.end()); buffer.insert(buffer.end(), eapol_buffer.begin(), eapol_buffer.end());
return buffer; return buffer;
} }

View File

@ -519,9 +519,9 @@ struct CTRPollFD {
CTRPollFD result; CTRPollFD result;
result.events.hex = Events::TranslateTo3DS(fd.events, has_libctru_bug).hex; result.events.hex = Events::TranslateTo3DS(fd.events, has_libctru_bug).hex;
result.revents.hex = Events::TranslateTo3DS(fd.revents, has_libctru_bug).hex; result.revents.hex = Events::TranslateTo3DS(fd.revents, has_libctru_bug).hex;
for (auto iter = socu.open_sockets.begin(); iter != socu.open_sockets.end(); ++iter) { for (const auto& socket : socu.open_sockets) {
if (iter->second.socket_fd == fd.fd) { if (socket.second.socket_fd == fd.fd) {
result.fd = iter->first; result.fd = socket.first;
break; break;
} }
} }
@ -662,7 +662,8 @@ struct CTRAddrInfo {
}; };
ctr_addr.ai_addrlen = static_cast<s32_le>(ctr_addr.ai_addr.raw.len); ctr_addr.ai_addrlen = static_cast<s32_le>(ctr_addr.ai_addr.raw.len);
if (addr.ai_canonname) if (addr.ai_canonname)
std::strncpy(ctr_addr.ai_canonname, addr.ai_canonname, sizeof(ctr_addr.ai_canonname)); std::strncpy(ctr_addr.ai_canonname, addr.ai_canonname,
sizeof(ctr_addr.ai_canonname) - 1);
return ctr_addr; return ctr_addr;
} }

View File

@ -45,7 +45,7 @@ struct ControllerState {
union { union {
struct { struct {
union { union {
u16_le hex; u16_le hex = 0;
BitField<0, 1, u16> a; BitField<0, 1, u16> a;
BitField<1, 1, u16> b; BitField<1, 1, u16> b;
@ -96,7 +96,7 @@ struct ControllerState {
struct { struct {
union { union {
u32_le hex; u32_le hex = 0;
BitField<0, 5, u32> battery_level; BitField<0, 5, u32> battery_level;
BitField<5, 1, u32> zl_not_held; BitField<5, 1, u32> zl_not_held;
@ -136,7 +136,7 @@ static u64 GetInputCount(const std::vector<u8>& input) {
break; break;
} }
ControllerState state; ControllerState state{};
std::memcpy(&state, input.data() + pos, sizeof(ControllerState)); std::memcpy(&state, input.data() + pos, sizeof(ControllerState));
if (state.type == ControllerStateType::PadAndCircle) { if (state.type == ControllerStateType::PadAndCircle) {
input_count++; input_count++;
@ -238,7 +238,7 @@ void Movie::CheckInputEnd() {
} }
void Movie::Play(Service::HID::PadState& pad_state, s16& circle_pad_x, s16& circle_pad_y) { void Movie::Play(Service::HID::PadState& pad_state, s16& circle_pad_x, s16& circle_pad_y) {
ControllerState s; ControllerState s{};
std::memcpy(&s, &recorded_input[current_byte], sizeof(ControllerState)); std::memcpy(&s, &recorded_input[current_byte], sizeof(ControllerState));
current_byte += sizeof(ControllerState); current_byte += sizeof(ControllerState);
current_input++; current_input++;
@ -270,7 +270,7 @@ void Movie::Play(Service::HID::PadState& pad_state, s16& circle_pad_x, s16& circ
} }
void Movie::Play(Service::HID::TouchDataEntry& touch_data) { void Movie::Play(Service::HID::TouchDataEntry& touch_data) {
ControllerState s; ControllerState s{};
std::memcpy(&s, &recorded_input[current_byte], sizeof(ControllerState)); std::memcpy(&s, &recorded_input[current_byte], sizeof(ControllerState));
current_byte += sizeof(ControllerState); current_byte += sizeof(ControllerState);
@ -287,7 +287,7 @@ void Movie::Play(Service::HID::TouchDataEntry& touch_data) {
} }
void Movie::Play(Service::HID::AccelerometerDataEntry& accelerometer_data) { void Movie::Play(Service::HID::AccelerometerDataEntry& accelerometer_data) {
ControllerState s; ControllerState s{};
std::memcpy(&s, &recorded_input[current_byte], sizeof(ControllerState)); std::memcpy(&s, &recorded_input[current_byte], sizeof(ControllerState));
current_byte += sizeof(ControllerState); current_byte += sizeof(ControllerState);
@ -304,7 +304,7 @@ void Movie::Play(Service::HID::AccelerometerDataEntry& accelerometer_data) {
} }
void Movie::Play(Service::HID::GyroscopeDataEntry& gyroscope_data) { void Movie::Play(Service::HID::GyroscopeDataEntry& gyroscope_data) {
ControllerState s; ControllerState s{};
std::memcpy(&s, &recorded_input[current_byte], sizeof(ControllerState)); std::memcpy(&s, &recorded_input[current_byte], sizeof(ControllerState));
current_byte += sizeof(ControllerState); current_byte += sizeof(ControllerState);
@ -321,7 +321,7 @@ void Movie::Play(Service::HID::GyroscopeDataEntry& gyroscope_data) {
} }
void Movie::Play(Service::IR::PadState& pad_state, s16& c_stick_x, s16& c_stick_y) { void Movie::Play(Service::IR::PadState& pad_state, s16& c_stick_x, s16& c_stick_y) {
ControllerState s; ControllerState s{};
std::memcpy(&s, &recorded_input[current_byte], sizeof(ControllerState)); std::memcpy(&s, &recorded_input[current_byte], sizeof(ControllerState));
current_byte += sizeof(ControllerState); current_byte += sizeof(ControllerState);
@ -339,7 +339,7 @@ void Movie::Play(Service::IR::PadState& pad_state, s16& c_stick_x, s16& c_stick_
} }
void Movie::Play(Service::IR::ExtraHIDResponse& extra_hid_response) { void Movie::Play(Service::IR::ExtraHIDResponse& extra_hid_response) {
ControllerState s; ControllerState s{};
std::memcpy(&s, &recorded_input[current_byte], sizeof(ControllerState)); std::memcpy(&s, &recorded_input[current_byte], sizeof(ControllerState));
current_byte += sizeof(ControllerState); current_byte += sizeof(ControllerState);
@ -371,7 +371,7 @@ void Movie::Record(const Service::HID::PadState& pad_state, const s16& circle_pa
const s16& circle_pad_y) { const s16& circle_pad_y) {
current_input++; current_input++;
ControllerState s; ControllerState s{};
s.type = ControllerStateType::PadAndCircle; s.type = ControllerStateType::PadAndCircle;
s.pad_and_circle.a.Assign(static_cast<u16>(pad_state.a)); s.pad_and_circle.a.Assign(static_cast<u16>(pad_state.a));
@ -396,7 +396,7 @@ void Movie::Record(const Service::HID::PadState& pad_state, const s16& circle_pa
} }
void Movie::Record(const Service::HID::TouchDataEntry& touch_data) { void Movie::Record(const Service::HID::TouchDataEntry& touch_data) {
ControllerState s; ControllerState s{};
s.type = ControllerStateType::Touch; s.type = ControllerStateType::Touch;
s.touch.x = touch_data.x; s.touch.x = touch_data.x;
@ -407,7 +407,7 @@ void Movie::Record(const Service::HID::TouchDataEntry& touch_data) {
} }
void Movie::Record(const Service::HID::AccelerometerDataEntry& accelerometer_data) { void Movie::Record(const Service::HID::AccelerometerDataEntry& accelerometer_data) {
ControllerState s; ControllerState s{};
s.type = ControllerStateType::Accelerometer; s.type = ControllerStateType::Accelerometer;
s.accelerometer.x = accelerometer_data.x; s.accelerometer.x = accelerometer_data.x;
@ -418,7 +418,7 @@ void Movie::Record(const Service::HID::AccelerometerDataEntry& accelerometer_dat
} }
void Movie::Record(const Service::HID::GyroscopeDataEntry& gyroscope_data) { void Movie::Record(const Service::HID::GyroscopeDataEntry& gyroscope_data) {
ControllerState s; ControllerState s{};
s.type = ControllerStateType::Gyroscope; s.type = ControllerStateType::Gyroscope;
s.gyroscope.x = gyroscope_data.x; s.gyroscope.x = gyroscope_data.x;
@ -430,7 +430,7 @@ void Movie::Record(const Service::HID::GyroscopeDataEntry& gyroscope_data) {
void Movie::Record(const Service::IR::PadState& pad_state, const s16& c_stick_x, void Movie::Record(const Service::IR::PadState& pad_state, const s16& c_stick_x,
const s16& c_stick_y) { const s16& c_stick_y) {
ControllerState s; ControllerState s{};
s.type = ControllerStateType::IrRst; s.type = ControllerStateType::IrRst;
s.ir_rst.x = c_stick_x; s.ir_rst.x = c_stick_x;
@ -442,7 +442,7 @@ void Movie::Record(const Service::IR::PadState& pad_state, const s16& c_stick_x,
} }
void Movie::Record(const Service::IR::ExtraHIDResponse& extra_hid_response) { void Movie::Record(const Service::IR::ExtraHIDResponse& extra_hid_response) {
ControllerState s; ControllerState s{};
s.type = ControllerStateType::ExtraHidResponse; s.type = ControllerStateType::ExtraHidResponse;
s.extra_hid_response.battery_level.Assign(extra_hid_response.buttons.battery_level); s.extra_hid_response.battery_level.Assign(extra_hid_response.buttons.battery_level);

View File

@ -1018,7 +1018,7 @@ public:
} }
Common::ParamPackage GetNextInput() override { Common::ParamPackage GetNextInput() override {
SDL_Event event; SDL_Event event{};
while (state.event_queue.Pop(event)) { while (state.event_queue.Pop(event)) {
if (event.type != SDL_JOYAXISMOTION || std::abs(event.jaxis.value / 32767.0) < 0.5) { if (event.type != SDL_JOYAXISMOTION || std::abs(event.jaxis.value / 32767.0) < 0.5) {
continue; continue;

View File

@ -85,42 +85,42 @@ Packet& Packet::operator>>(u8& out_data) {
} }
Packet& Packet::operator>>(s16& out_data) { Packet& Packet::operator>>(s16& out_data) {
s16 value; s16 value = 0;
Read(&value, sizeof(value)); Read(&value, sizeof(value));
out_data = ntohs(value); out_data = ntohs(value);
return *this; return *this;
} }
Packet& Packet::operator>>(u16& out_data) { Packet& Packet::operator>>(u16& out_data) {
u16 value; u16 value = 0;
Read(&value, sizeof(value)); Read(&value, sizeof(value));
out_data = ntohs(value); out_data = ntohs(value);
return *this; return *this;
} }
Packet& Packet::operator>>(s32& out_data) { Packet& Packet::operator>>(s32& out_data) {
s32 value; s32 value = 0;
Read(&value, sizeof(value)); Read(&value, sizeof(value));
out_data = ntohl(value); out_data = ntohl(value);
return *this; return *this;
} }
Packet& Packet::operator>>(u32& out_data) { Packet& Packet::operator>>(u32& out_data) {
u32 value; u32 value = 0;
Read(&value, sizeof(value)); Read(&value, sizeof(value));
out_data = ntohl(value); out_data = ntohl(value);
return *this; return *this;
} }
Packet& Packet::operator>>(s64& out_data) { Packet& Packet::operator>>(s64& out_data) {
s64 value; s64 value = 0;
Read(&value, sizeof(value)); Read(&value, sizeof(value));
out_data = ntohll(value); out_data = ntohll(value);
return *this; return *this;
} }
Packet& Packet::operator>>(u64& out_data) { Packet& Packet::operator>>(u64& out_data) {
u64 value; u64 value = 0;
Read(&value, sizeof(value)); Read(&value, sizeof(value));
out_data = ntohll(value); out_data = ntohll(value);
return *this; return *this;

View File

@ -150,7 +150,7 @@ public:
setup.uniforms.f[0] = Common::MakeVec(vertex_num, vertex_num, vertex_num, vertex_num); setup.uniforms.f[0] = Common::MakeVec(vertex_num, vertex_num, vertex_num, vertex_num);
// The second uniform register and so on are used for receiving input vertices // The second uniform register and so on are used for receiving input vertices
buffer_cur = setup.uniforms.f + 1; buffer_cur = setup.uniforms.f.data() + 1;
main_vertex_num = regs.pipeline.variable_vertex_main_num_minus_1 + 1; main_vertex_num = regs.pipeline.variable_vertex_main_num_minus_1 + 1;
total_vertex_num = val; total_vertex_num = val;
@ -200,7 +200,7 @@ private:
template <class Archive> template <class Archive>
void save(Archive& ar, const unsigned int version) const { void save(Archive& ar, const unsigned int version) const {
serialize_common(this, ar, version); serialize_common(this, ar, version);
auto buffer_idx = static_cast<u32>(buffer_cur - setup.uniforms.f); auto buffer_idx = static_cast<u32>(buffer_cur - setup.uniforms.f.data());
ar << buffer_idx; ar << buffer_idx;
} }
@ -209,7 +209,7 @@ private:
serialize_common(this, ar, version); serialize_common(this, ar, version);
u32 buffer_idx; u32 buffer_idx;
ar >> buffer_idx; ar >> buffer_idx;
buffer_cur = setup.uniforms.f + buffer_idx; buffer_cur = setup.uniforms.f.data() + buffer_idx;
} }
BOOST_SERIALIZATION_SPLIT_MEMBER() BOOST_SERIALIZATION_SPLIT_MEMBER()
@ -229,7 +229,7 @@ public:
vs_output_num = regs.pipeline.vs_outmap_total_minus_1_a + 1; vs_output_num = regs.pipeline.vs_outmap_total_minus_1_a + 1;
ASSERT(vs_output_num == regs.pipeline.gs_config.stride_minus_1 + 1); ASSERT(vs_output_num == regs.pipeline.gs_config.stride_minus_1 + 1);
std::size_t vertex_num = regs.pipeline.gs_config.fixed_vertex_num_minus_1 + 1; std::size_t vertex_num = regs.pipeline.gs_config.fixed_vertex_num_minus_1 + 1;
buffer_cur = buffer_begin = setup.uniforms.f + regs.pipeline.gs_config.start_index; buffer_cur = buffer_begin = setup.uniforms.f.data() + regs.pipeline.gs_config.start_index;
buffer_end = buffer_begin + vs_output_num * vertex_num; buffer_end = buffer_begin + vs_output_num * vertex_num;
} }
@ -273,9 +273,9 @@ private:
template <class Archive> template <class Archive>
void save(Archive& ar, const unsigned int version) const { void save(Archive& ar, const unsigned int version) const {
serialize_common(this, ar, version); serialize_common(this, ar, version);
auto buffer_offset = static_cast<u32>(buffer_begin - setup.uniforms.f); auto buffer_offset = static_cast<u32>(buffer_begin - setup.uniforms.f.data());
auto buffer_idx = static_cast<u32>(buffer_cur - setup.uniforms.f); auto buffer_idx = static_cast<u32>(buffer_cur - setup.uniforms.f.data());
auto buffer_size = static_cast<u32>(buffer_end - setup.uniforms.f); auto buffer_size = static_cast<u32>(buffer_end - setup.uniforms.f.data());
ar << buffer_offset; ar << buffer_offset;
ar << buffer_idx; ar << buffer_idx;
ar << buffer_size; ar << buffer_size;
@ -288,9 +288,9 @@ private:
ar >> buffer_offset; ar >> buffer_offset;
ar >> buffer_idx; ar >> buffer_idx;
ar >> buffer_size; ar >> buffer_size;
buffer_begin = setup.uniforms.f + buffer_offset; buffer_begin = setup.uniforms.f.data() + buffer_offset;
buffer_cur = setup.uniforms.f + buffer_idx; buffer_cur = setup.uniforms.f.data() + buffer_idx;
buffer_end = setup.uniforms.f + buffer_size; buffer_end = setup.uniforms.f.data() + buffer_size;
} }
BOOST_SERIALIZATION_SPLIT_MEMBER() BOOST_SERIALIZATION_SPLIT_MEMBER()

View File

@ -32,8 +32,7 @@ void Shutdown() {
template <typename T> template <typename T>
void Zero(T& o) { void Zero(T& o) {
static_assert(std::is_trivially_copyable_v<T>, static_assert(std::is_trivial_v<T>, "It's undefined behavior to memset a non-trivial type");
"It's undefined behavior to memset a non-trivially copyable type");
memset(&o, 0, sizeof(o)); memset(&o, 0, sizeof(o));
} }
@ -56,10 +55,10 @@ State::State() : geometry_pipeline(*this) {
void State::Reset() { void State::Reset() {
Zero(regs); Zero(regs);
Zero(vs); vs = {};
Zero(gs); gs = {};
Zero(cmd_list); Zero(cmd_list);
Zero(immediate); immediate = {};
primitive_assembler.Reconfigure(PipelineRegs::TriangleTopology::List); primitive_assembler.Reconfigure(PipelineRegs::TriangleTopology::List);
vs_float_regs_counter = 0; vs_float_regs_counter = 0;
vs_uniform_write_buffer.fill(0); vs_uniform_write_buffer.fill(0);

View File

@ -241,7 +241,7 @@ private:
struct Uniforms { struct Uniforms {
// The float uniforms are accessed by the shader JIT using SSE instructions, and are // The float uniforms are accessed by the shader JIT using SSE instructions, and are
// therefore required to be 16-byte aligned. // therefore required to be 16-byte aligned.
alignas(16) Common::Vec4<float24> f[96]; alignas(16) std::array<Common::Vec4<float24>, 96> f;
std::array<bool, 16> b; std::array<bool, 16> b;
std::array<Common::Vec4<u8>, 4> i; std::array<Common::Vec4<u8>, 4> i;