From 7bf19759d33df2482c70eabd0bf5119560823194 Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Sat, 11 Jun 2022 16:52:27 -0400 Subject: [PATCH] fix goalc crash and clang warnings (#1441) --- common/cross_sockets/XSocket.cpp | 2 +- common/serialization/subtitles/subtitles.h | 2 +- decompiler/analysis/insert_lets.cpp | 10 +++++----- game/graphics/pipelines/opengl.cpp | 2 +- game/system/IOP_Kernel.cpp | 4 ++-- game/tools/subtitles/subtitle_editor.cpp | 18 +++++++++--------- third-party/imgui/imgui_stdlib.cpp | 12 ++++++------ 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/common/cross_sockets/XSocket.cpp b/common/cross_sockets/XSocket.cpp index 555cb16cf..c6f4fe05e 100644 --- a/common/cross_sockets/XSocket.cpp +++ b/common/cross_sockets/XSocket.cpp @@ -146,7 +146,7 @@ int set_socket_timeout(int socket, long microSeconds) { int write_to_socket(int socket, const char* buf, int len) { int bytes_wrote = 0; #ifdef __linux - bytes_wrote = write(socket, buf, len); + bytes_wrote = send(socket, buf, len, MSG_NOSIGNAL); #elif _WIN32 bytes_wrote = send(socket, buf, len, 0); #endif diff --git a/common/serialization/subtitles/subtitles.h b/common/serialization/subtitles/subtitles.h index c400cf2cf..7fc0a9443 100644 --- a/common/serialization/subtitles/subtitles.h +++ b/common/serialization/subtitles/subtitles.h @@ -92,7 +92,7 @@ class GameSubtitleSceneInfo { std::string speaker_utf8; bool offscreen; - bool operator<(const SubtitleLine& line) const { return (frame < line.frame); } + bool operator<(const SubtitleLine& other) const { return (frame < other.frame); } }; GameSubtitleSceneInfo() {} diff --git a/decompiler/analysis/insert_lets.cpp b/decompiler/analysis/insert_lets.cpp index 6416efc26..6e58a4068 100644 --- a/decompiler/analysis/insert_lets.cpp +++ b/decompiler/analysis/insert_lets.cpp @@ -456,7 +456,7 @@ FormElement* rewrite_as_send_event(LetElement* in, {Matcher::any(0), Matcher::reg(block_var_reg)}); auto mr_with_shell = rewrite_shelled_return_form( call_matcher, body->at(3 + param_count), env, pool, - [&](FormElement* s_in, const MatchResult& mr, const Env& env, FormPool& pool) { + [&](FormElement* /*s_in*/, const MatchResult& mr, const Env& /*env*/, FormPool& pool) { Form* send_destination = mr.maps.forms.at(0); // time to build the macro! @@ -1306,7 +1306,7 @@ FormElement* rewrite_proc_new(LetElement* in, const Env& env, FormPool& pool) { {Matcher::reg(ra.reg()), Matcher::any(1)}), Matcher::any(2)})), macro_form, env, pool, - [&](FormElement* s_in, const MatchResult& mr, const Env& env, FormPool& pool) { + [&](FormElement* s_in, const MatchResult& /*mr*/, const Env& env, FormPool& pool) { auto as_when = dynamic_cast(s_in); const auto& when_body = as_when->entries.front().body->elts(); @@ -1382,7 +1382,7 @@ FormElement* rewrite_proc_new(LetElement* in, const Env& env, FormPool& pool) { // args // this would be a great place to do some hacky stuff! hmm, maybe i will... - for (int i = 2; i < as_func->elts().size(); ++i) { + for (size_t i = 2; i < as_func->elts().size(); ++i) { args.push_back(as_func->elts().at(i)); } @@ -1541,7 +1541,7 @@ FormElement* rewrite_attack_info(LetElement* in, const Env& env, FormPool& pool) // (static-attack-info :mask etc) auto mr_with_shell = rewrite_shelled_return_form( Matcher::reg(block_var_reg), in->body()->at(in->body()->size() - 1), env, pool, - [&](FormElement* s_in, const MatchResult& mr, const Env& env, FormPool& pool) { + [&](FormElement* /*s_in*/, const MatchResult& /*mr*/, const Env& env, FormPool& pool) { // time to build the macro! std::vector macro_args; @@ -1733,7 +1733,7 @@ FormElement* rewrite_rand_float_gen(LetElement* in, const Env& env, FormPool& po } else { auto mr_res = rewrite_shelled_return_form( matcher_res, in->body()->at(0), env, pool, - [&](FormElement* s_in, const MatchResult& mr, const Env& env, FormPool& pool) { + [&](FormElement* /*s_in*/, const MatchResult& /*mr*/, const Env& /*env*/, FormPool& pool) { auto head = GenericOperator::make_function(pool.form("rand-float-gen")); return gen ? pool.form(head, gen) : pool.form(head); diff --git a/game/graphics/pipelines/opengl.cpp b/game/graphics/pipelines/opengl.cpp index f534e95d3..eaa0b3b68 100644 --- a/game/graphics/pipelines/opengl.cpp +++ b/game/graphics/pipelines/opengl.cpp @@ -252,7 +252,7 @@ void render_game_frame(int width, int height, int lbox_width, int lbox_height) { if (options.save_screenshot) { // ensure the screenshot has an extension std::string temp_path = g_gfx_data->debug_gui.screenshot_name(); - if (endsWith(temp_path, ".png")) { + if (!endsWith(temp_path, ".png")) { temp_path += ".png"; } options.screenshot_path = make_output_file_name(temp_path); diff --git a/game/system/IOP_Kernel.cpp b/game/system/IOP_Kernel.cpp index a1b16f57e..09c45c0ba 100644 --- a/game/system/IOP_Kernel.cpp +++ b/game/system/IOP_Kernel.cpp @@ -109,10 +109,10 @@ bool IOP_Kernel::OnlyThreadAlive(s32 thid) { bool yes = false; for (u64 i = 0; i < threads.size(); i++) { if (threads[i].started && !threads[i].done) { - if (i != thid) { + if ((s32)i != thid) { return false; } - if (i == thid) { + if ((s32)i == thid) { yes = true; } } diff --git a/game/tools/subtitles/subtitle_editor.cpp b/game/tools/subtitles/subtitle_editor.cpp index 7236e06b0..d8f6d341b 100644 --- a/game/tools/subtitles/subtitle_editor.cpp +++ b/game/tools/subtitles/subtitle_editor.cpp @@ -282,7 +282,7 @@ void SubtitleEditor::draw_all_scenes(std::string group_name, bool base_cutscenes if (ImGui::TreeNode( fmt::format("{}-{}", scene_name, base_cutscenes ? m_base_language : m_current_language) .c_str(), - scene_name.c_str())) { + "%s", scene_name.c_str())) { if (base_cutscenes || is_current_scene) { ImGui::PopStyleColor(); } @@ -313,8 +313,8 @@ void SubtitleEditor::draw_all_scenes(std::string group_name, bool base_cutscenes ImGui::NewLine(); } if (ImGui::BeginCombo("Sorting Group", scene_info.m_sorting_group.c_str())) { - for (int i = 0; i < m_subtitle_db.m_subtitle_groups->m_group_order.size(); ++i) { - const bool isSelected = (scene_info.m_sorting_group_idx == i); + for (size_t i = 0; i < m_subtitle_db.m_subtitle_groups->m_group_order.size(); ++i) { + const bool isSelected = (scene_info.m_sorting_group_idx == (int)i); if (ImGui::Selectable(m_subtitle_db.m_subtitle_groups->m_group_order[i].c_str(), isSelected)) { // Remove from current group @@ -332,7 +332,7 @@ void SubtitleEditor::draw_all_scenes(std::string group_name, bool base_cutscenes } ImGui::EndCombo(); } - for (int i = 0; i < scene_info.m_lines.size(); i++) { + for (size_t i = 0; i < scene_info.m_lines.size(); i++) { auto& subtitleLine = scene_info.m_lines.at(i); std::string summary; if (subtitleLine.line_utf8.empty()) { @@ -346,7 +346,7 @@ void SubtitleEditor::draw_all_scenes(std::string group_name, bool base_cutscenes } else if (subtitleLine.offscreen) { ImGui::PushStyleColor(ImGuiCol_Text, m_offscreen_text_color); } - if (ImGui::TreeNode(fmt::format("{}", i).c_str(), summary.c_str())) { + if (ImGui::TreeNode(fmt::format("{}", i).c_str(), "%s", summary.c_str())) { if (subtitleLine.line_utf8.empty() || subtitleLine.offscreen) { ImGui::PopStyleColor(); } @@ -400,8 +400,8 @@ void SubtitleEditor::draw_current_cutscene() { ImGui::NewLine(); } if (ImGui::BeginCombo("Sorting Group", m_current_scene->m_sorting_group.c_str())) { - for (int i = 0; i < m_subtitle_db.m_subtitle_groups->m_group_order.size(); ++i) { - const bool isSelected = (m_current_scene->m_sorting_group_idx == i); + for (size_t i = 0; i < m_subtitle_db.m_subtitle_groups->m_group_order.size(); ++i) { + const bool isSelected = (m_current_scene->m_sorting_group_idx == (int)i); if (ImGui::Selectable(m_subtitle_db.m_subtitle_groups->m_group_order[i].c_str(), isSelected)) { // Remove from current group @@ -452,7 +452,7 @@ void SubtitleEditor::draw_current_cutscene() { } } ImGui::NewLine(); - for (int i = 0; i < m_current_scene->m_lines.size(); i++) { + for (size_t i = 0; i < m_current_scene->m_lines.size(); i++) { auto& subtitleLine = m_current_scene->m_lines.at(i); std::string summary; if (subtitleLine.line_utf8.empty()) { @@ -466,7 +466,7 @@ void SubtitleEditor::draw_current_cutscene() { } else if (subtitleLine.offscreen) { ImGui::PushStyleColor(ImGuiCol_Text, m_offscreen_text_color); } - if (ImGui::TreeNode(fmt::format("{}", i).c_str(), summary.c_str())) { + if (ImGui::TreeNode(fmt::format("{}", i).c_str(), "%s", summary.c_str())) { if (subtitleLine.line_utf8.empty() || subtitleLine.offscreen) { ImGui::PopStyleColor(); } diff --git a/third-party/imgui/imgui_stdlib.cpp b/third-party/imgui/imgui_stdlib.cpp index bffb7fa7f..500f65a33 100644 --- a/third-party/imgui/imgui_stdlib.cpp +++ b/third-party/imgui/imgui_stdlib.cpp @@ -22,7 +22,7 @@ static int InputTextCallback(ImGuiInputTextCallbackData* data) { std::string* str = user_data->Str; IM_ASSERT(data->Buf == str->c_str()); str->resize(data->BufTextLen); - data->Buf = (char*)str->c_str(); + data->Buf = str->data(); } else if (user_data->ChainCallback) { // Forward to user callback, if any data->UserData = user_data->ChainCallbackUserData; @@ -43,7 +43,7 @@ bool ImGui::InputText(const char* label, cb_user_data.Str = str; cb_user_data.ChainCallback = callback; cb_user_data.ChainCallbackUserData = user_data; - return InputText(label, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, + return InputText(label, str->data(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data); } @@ -60,8 +60,8 @@ bool ImGui::InputTextMultiline(const char* label, cb_user_data.Str = str; cb_user_data.ChainCallback = callback; cb_user_data.ChainCallbackUserData = user_data; - return InputTextMultiline(label, (char*)str->c_str(), str->capacity() + 1, size, flags, - InputTextCallback, &cb_user_data); + return InputTextMultiline(label, str->data(), str->capacity() + 1, size, flags, InputTextCallback, + &cb_user_data); } bool ImGui::InputTextWithHint(const char* label, @@ -77,6 +77,6 @@ bool ImGui::InputTextWithHint(const char* label, cb_user_data.Str = str; cb_user_data.ChainCallback = callback; cb_user_data.ChainCallbackUserData = user_data; - return InputTextWithHint(label, hint, (char*)str->c_str(), str->capacity() + 1, flags, - InputTextCallback, &cb_user_data); + return InputTextWithHint(label, hint, str->data(), str->capacity() + 1, flags, InputTextCallback, + &cb_user_data); }