core: fix warnings

This commit is contained in:
SachinVin 2023-06-09 22:48:42 +05:30
parent 796e8a9f24
commit 8eb89c260d
12 changed files with 55 additions and 42 deletions

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);