From 0e53dd642c44a613fdc1fa683ea373516e67c983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Wed, 28 Sep 2022 15:59:08 +0200 Subject: [PATCH] Fix MSVC warning C4706: assignment within conditional expression Part of #66537. --- core/string/ustring.cpp | 25 +++++---- core/templates/hashfuncs.h | 5 +- editor/plugins/canvas_item_editor_plugin.cpp | 24 ++++---- modules/theora/video_stream_theora.cpp | 56 ++++++++++--------- modules/vorbis/audio_stream_ogg_vorbis.cpp | 27 ++++++--- .../vorbis/resource_importer_ogg_vorbis.cpp | 18 ++++-- platform/windows/godot_windows.cpp | 4 +- scene/gui/file_dialog.cpp | 10 ++-- 8 files changed, 102 insertions(+), 67 deletions(-) diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index d8b93998afb..75b797d3977 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -2624,10 +2624,11 @@ double String::to_float() const { uint32_t String::hash(const char *p_cstr) { uint32_t hashv = 5381; - uint32_t c; + uint32_t c = *p_cstr++; - while ((c = *p_cstr++)) { + while (c) { hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */ + c = *p_cstr++; } return hashv; @@ -2653,10 +2654,11 @@ uint32_t String::hash(const wchar_t *p_cstr, int p_len) { uint32_t String::hash(const wchar_t *p_cstr) { uint32_t hashv = 5381; - uint32_t c; + uint32_t c = *p_cstr++; - while ((c = *p_cstr++)) { + while (c) { hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */ + c = *p_cstr++; } return hashv; @@ -2673,10 +2675,11 @@ uint32_t String::hash(const char32_t *p_cstr, int p_len) { uint32_t String::hash(const char32_t *p_cstr) { uint32_t hashv = 5381; - uint32_t c; + uint32_t c = *p_cstr++; - while ((c = *p_cstr++)) { + while (c) { hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */ + c = *p_cstr++; } return hashv; @@ -2687,10 +2690,11 @@ uint32_t String::hash() const { const char32_t *chr = get_data(); uint32_t hashv = 5381; - uint32_t c; + uint32_t c = *chr++; - while ((c = *chr++)) { + while (c) { hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */ + c = *chr++; } return hashv; @@ -2701,10 +2705,11 @@ uint64_t String::hash64() const { const char32_t *chr = get_data(); uint64_t hashv = 5381; - uint64_t c; + uint64_t c = *chr++; - while ((c = *chr++)) { + while (c) { hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */ + c = *chr++; } return hashv; diff --git a/core/templates/hashfuncs.h b/core/templates/hashfuncs.h index d85cdf7adc7..456a7b01edb 100644 --- a/core/templates/hashfuncs.h +++ b/core/templates/hashfuncs.h @@ -61,10 +61,11 @@ static _FORCE_INLINE_ uint32_t hash_djb2(const char *p_cstr) { const unsigned char *chr = (const unsigned char *)p_cstr; uint32_t hash = 5381; - uint32_t c; + uint32_t c = *chr++; - while ((c = *chr++)) { + while (c) { hash = ((hash << 5) + hash) ^ c; /* hash * 33 ^ c */ + c = *chr++; } return hash; diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 8dc08e3a930..84b8b4aed8c 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -2535,30 +2535,32 @@ void CanvasItemEditor::_gui_input_viewport(const Ref &p_event) { bool release_lmb = (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT); // Required to properly release some stuff (e.g. selection box) while panning. if (EditorSettings::get_singleton()->get("editors/panning/simple_panning") || !pan_pressed || release_lmb) { - if ((accepted = _gui_input_rulers_and_guides(p_event))) { + accepted = true; + if (_gui_input_rulers_and_guides(p_event)) { // print_line("Rulers and guides"); - } else if ((accepted = EditorNode::get_singleton()->get_editor_plugins_over()->forward_gui_input(p_event))) { + } else if (EditorNode::get_singleton()->get_editor_plugins_over()->forward_gui_input(p_event)) { // print_line("Plugin"); - } else if ((accepted = _gui_input_open_scene_on_double_click(p_event))) { + } else if (_gui_input_open_scene_on_double_click(p_event)) { // print_line("Open scene on double click"); - } else if ((accepted = _gui_input_scale(p_event))) { + } else if (_gui_input_scale(p_event)) { // print_line("Set scale"); - } else if ((accepted = _gui_input_pivot(p_event))) { + } else if (_gui_input_pivot(p_event)) { // print_line("Set pivot"); - } else if ((accepted = _gui_input_resize(p_event))) { + } else if (_gui_input_resize(p_event)) { // print_line("Resize"); - } else if ((accepted = _gui_input_rotate(p_event))) { + } else if (_gui_input_rotate(p_event)) { // print_line("Rotate"); - } else if ((accepted = _gui_input_move(p_event))) { + } else if (_gui_input_move(p_event)) { // print_line("Move"); - } else if ((accepted = _gui_input_anchors(p_event))) { + } else if (_gui_input_anchors(p_event)) { // print_line("Anchors"); - } else if ((accepted = _gui_input_select(p_event))) { + } else if (_gui_input_select(p_event)) { // print_line("Selection"); - } else if ((accepted = _gui_input_ruler_tool(p_event))) { + } else if (_gui_input_ruler_tool(p_event)) { // print_line("Measure"); } else { // print_line("Not accepted"); + accepted = false; } } diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index cbeb073ee50..57f055ca42c 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -91,8 +91,6 @@ void VideoStreamPlaybackTheora::video_write() { uint8_t *w = frame_data.ptrw(); char *dst = (char *)w; - //uv_offset=(ti.pic_x/2)+(yuv[1].stride)*(ti.pic_y/2); - if (px_fmt == TH_PF_444) { yuv444_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[1].data, (uint8_t *)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2); @@ -101,7 +99,7 @@ void VideoStreamPlaybackTheora::video_write() { } else if (px_fmt == TH_PF_420) { yuv420_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[1].data, (uint8_t *)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2); - }; + } format = Image::FORMAT_RGBA8; } @@ -123,7 +121,7 @@ void VideoStreamPlaybackTheora::clear() { if (vorbis_p >= 3) { vorbis_block_clear(&vb); vorbis_dsp_clear(&vd); - }; + } vorbis_comment_clear(&vc); vorbis_info_clear(&vi); vorbis_p = 0; @@ -154,7 +152,7 @@ void VideoStreamPlaybackTheora::clear() { file.unref(); playing = false; -}; +} void VideoStreamPlaybackTheora::set_file(const String &p_file) { ERR_FAIL_COND(playing); @@ -174,7 +172,6 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { ring_buffer.write(read_buffer.ptr(), read); thread.start(_streaming_thread, this); - #endif ogg_sync_init(&oy); @@ -245,6 +242,12 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { /* we're expecting more header packets. */ while ((theora_p && theora_p < 3) || (vorbis_p && vorbis_p < 3)) { +#ifdef _MSC_VER + // Make exception for these assignments in conditional expression. +#pragma warning(push) +#pragma warning(disable : 4706) +#endif + int ret; /* look for further theora headers */ @@ -281,6 +284,10 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { } } +#ifdef _MSC_VER +#pragma warning(pop) +#endif + /* The header pages/packets will arrive before anything else we care about, or the stream is not obeying spec */ @@ -355,14 +362,14 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { buffering = true; time = 0; audio_frames_wrote = 0; -}; +} double VideoStreamPlaybackTheora::get_time() const { // FIXME: AudioServer output latency was fixed in af9bb0e, previously it used to // systematically return 0. Now that it gives a proper latency, it broke this // code where the delay compensation likely never really worked. return time - /* AudioServer::get_singleton()->get_output_latency() - */ delay_compensation; -}; +} Ref VideoStreamPlaybackTheora::get_texture() const { return texture; @@ -376,7 +383,7 @@ void VideoStreamPlaybackTheora::update(double p_delta) { if (!playing || paused) { //printf("not playing\n"); return; - }; + } #ifdef THEORA_USE_THREAD_STREAMING thread_sem->post(); @@ -444,7 +451,7 @@ void VideoStreamPlaybackTheora::update(double p_delta) { } } else { /* we need more data; break out to suck in another page */ break; - }; + } } audio_done = videobuf_time < (audio_frames_wrote / float(vi.rate)); @@ -507,7 +514,7 @@ void VideoStreamPlaybackTheora::update(double p_delta) { //printf("video done, stopping\n"); stop(); return; - }; + } if (!frame_done || !audio_done) { //what's the point of waiting for audio to grab a page? @@ -539,7 +546,7 @@ void VideoStreamPlaybackTheora::update(double p_delta) { } video_write(); -}; +} void VideoStreamPlaybackTheora::play() { if (!playing) { @@ -551,7 +558,7 @@ void VideoStreamPlaybackTheora::play() { playing = true; delay_compensation = ProjectSettings::get_singleton()->get("audio/video/video_delay_compensation_ms"); delay_compensation /= 1000.0; -}; +} void VideoStreamPlaybackTheora::stop() { if (playing) { @@ -560,42 +567,42 @@ void VideoStreamPlaybackTheora::stop() { } playing = false; time = 0; -}; +} bool VideoStreamPlaybackTheora::is_playing() const { return playing; -}; +} void VideoStreamPlaybackTheora::set_paused(bool p_paused) { paused = p_paused; -}; +} bool VideoStreamPlaybackTheora::is_paused() const { return paused; -}; +} void VideoStreamPlaybackTheora::set_loop(bool p_enable) { } bool VideoStreamPlaybackTheora::has_loop() const { return false; -}; +} double VideoStreamPlaybackTheora::get_length() const { return 0; -}; +} String VideoStreamPlaybackTheora::get_stream_name() const { return ""; -}; +} int VideoStreamPlaybackTheora::get_loop_count() const { return 0; -}; +} double VideoStreamPlaybackTheora::get_playback_position() const { return get_time(); -}; +} void VideoStreamPlaybackTheora::seek(double p_time) { WARN_PRINT_ONCE("Seeking in Theora videos is not implemented yet (it's only supported for GDExtension-provided video streams)."); @@ -650,15 +657,14 @@ VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() { thread_sem = Semaphore::create(); #endif -}; +} VideoStreamPlaybackTheora::~VideoStreamPlaybackTheora() { #ifdef THEORA_USE_THREAD_STREAMING - memdelete(thread_sem); #endif clear(); -}; +} void VideoStreamTheora::_bind_methods() { ClassDB::bind_method(D_METHOD("set_file", "file"), &VideoStreamTheora::set_file); diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp index bd220df1042..9cb61a83f2c 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp @@ -153,8 +153,11 @@ int AudioStreamPlaybackOggVorbis::_mix_frames_vorbis(AudioFrame *p_buffer, int p return -1; } - ERR_FAIL_COND_V_MSG((err = vorbis_synthesis(&block, packet)), 0, "Error during vorbis synthesis " + itos(err)); - ERR_FAIL_COND_V_MSG((err = vorbis_synthesis_blockin(&dsp_state, &block)), 0, "Error during vorbis block processing " + itos(err)); + err = vorbis_synthesis(&block, packet); + ERR_FAIL_COND_V_MSG(err != 0, 0, "Error during vorbis synthesis " + itos(err)); + + err = vorbis_synthesis_blockin(&dsp_state, &block); + ERR_FAIL_COND_V_MSG(err != 0, 0, "Error during vorbis block processing " + itos(err)); have_packets_left = !packet->e_o_s; } @@ -290,11 +293,15 @@ void AudioStreamPlaybackOggVorbis::seek(double p_time) { headers_remaining = 3; } if (!headers_remaining) { - ERR_FAIL_COND_MSG((err = vorbis_synthesis(&block, packet)), "Error during vorbis synthesis " + itos(err)); - ERR_FAIL_COND_MSG((err = vorbis_synthesis_blockin(&dsp_state, &block)), "Error during vorbis block processing " + itos(err)); + err = vorbis_synthesis(&block, packet); + ERR_FAIL_COND_MSG(err != 0, "Error during vorbis synthesis " + itos(err)); + + err = vorbis_synthesis_blockin(&dsp_state, &block); + ERR_FAIL_COND_MSG(err != 0, "Error during vorbis block processing " + itos(err)); int samples_out = vorbis_synthesis_pcmout(&dsp_state, nullptr); - ERR_FAIL_COND_MSG((err = vorbis_synthesis_read(&dsp_state, samples_out)), "Error during vorbis read updating " + itos(err)); + err = vorbis_synthesis_read(&dsp_state, samples_out); + ERR_FAIL_COND_MSG(err != 0, "Error during vorbis read updating " + itos(err)); samples_in_page += samples_out; @@ -341,12 +348,16 @@ void AudioStreamPlaybackOggVorbis::seek(double p_time) { headers_remaining = 3; } if (!headers_remaining) { - ERR_FAIL_COND_MSG((err = vorbis_synthesis(&block, packet)), "Error during vorbis synthesis " + itos(err)); - ERR_FAIL_COND_MSG((err = vorbis_synthesis_blockin(&dsp_state, &block)), "Error during vorbis block processing " + itos(err)); + err = vorbis_synthesis(&block, packet); + ERR_FAIL_COND_MSG(err != 0, "Error during vorbis synthesis " + itos(err)); + + err = vorbis_synthesis_blockin(&dsp_state, &block); + ERR_FAIL_COND_MSG(err != 0, "Error during vorbis block processing " + itos(err)); int samples_out = vorbis_synthesis_pcmout(&dsp_state, nullptr); int read_samples = samples_to_burn > samples_out ? samples_out : samples_to_burn; - ERR_FAIL_COND_MSG((err = vorbis_synthesis_read(&dsp_state, samples_out)), "Error during vorbis read updating " + itos(err)); + err = vorbis_synthesis_read(&dsp_state, samples_out); + ERR_FAIL_COND_MSG(err != 0, "Error during vorbis read updating " + itos(err)); samples_to_burn -= read_samples; if (samples_to_burn <= 0) { diff --git a/modules/vorbis/resource_importer_ogg_vorbis.cpp b/modules/vorbis/resource_importer_ogg_vorbis.cpp index bf5f7206b89..a491c3d3fbd 100644 --- a/modules/vorbis/resource_importer_ogg_vorbis.cpp +++ b/modules/vorbis/resource_importer_ogg_vorbis.cpp @@ -110,15 +110,18 @@ Ref ResourceImporterOggVorbis::import_ogg_vorbis(const Str size_t packet_count = 0; bool done = false; while (!done) { - ERR_FAIL_COND_V_MSG((err = ogg_sync_check(&sync_state)), Ref(), "Ogg sync error " + itos(err)); + err = ogg_sync_check(&sync_state); + ERR_FAIL_COND_V_MSG(err != 0, Ref(), "Ogg sync error " + itos(err)); while (ogg_sync_pageout(&sync_state, &page) != 1) { if (cursor >= len) { done = true; break; } - ERR_FAIL_COND_V_MSG((err = ogg_sync_check(&sync_state)), Ref(), "Ogg sync error " + itos(err)); + err = ogg_sync_check(&sync_state); + ERR_FAIL_COND_V_MSG(err != 0, Ref(), "Ogg sync error " + itos(err)); char *sync_buf = ogg_sync_buffer(&sync_state, OGG_SYNC_BUFFER_SIZE); - ERR_FAIL_COND_V_MSG((err = ogg_sync_check(&sync_state)), Ref(), "Ogg sync error " + itos(err)); + err = ogg_sync_check(&sync_state); + ERR_FAIL_COND_V_MSG(err != 0, Ref(), "Ogg sync error " + itos(err)); ERR_FAIL_COND_V(cursor > len, Ref()); size_t copy_size = len - cursor; if (copy_size > OGG_SYNC_BUFFER_SIZE) { @@ -127,12 +130,14 @@ Ref ResourceImporterOggVorbis::import_ogg_vorbis(const Str memcpy(sync_buf, &file_data[cursor], copy_size); ogg_sync_wrote(&sync_state, copy_size); cursor += copy_size; - ERR_FAIL_COND_V_MSG((err = ogg_sync_check(&sync_state)), Ref(), "Ogg sync error " + itos(err)); + err = ogg_sync_check(&sync_state); + ERR_FAIL_COND_V_MSG(err != 0, Ref(), "Ogg sync error " + itos(err)); } if (done) { break; } - ERR_FAIL_COND_V_MSG((err = ogg_sync_check(&sync_state)), Ref(), "Ogg sync error " + itos(err)); + err = ogg_sync_check(&sync_state); + ERR_FAIL_COND_V_MSG(err != 0, Ref(), "Ogg sync error " + itos(err)); // Have a page now. if (!initialized_stream) { @@ -142,7 +147,8 @@ Ref ResourceImporterOggVorbis::import_ogg_vorbis(const Str initialized_stream = true; } ogg_stream_pagein(&stream_state, &page); - ERR_FAIL_COND_V_MSG((err = ogg_stream_check(&stream_state)), Ref(), "Ogg stream error " + itos(err)); + err = ogg_stream_check(&stream_state); + ERR_FAIL_COND_V_MSG(err != 0, Ref(), "Ogg stream error " + itos(err)); int desync_iters = 0; Vector> packet_data; diff --git a/platform/windows/godot_windows.cpp b/platform/windows/godot_windows.cpp index 72920d28167..13602f7cbcd 100644 --- a/platform/windows/godot_windows.cpp +++ b/platform/windows/godot_windows.cpp @@ -87,7 +87,8 @@ CommandLineToArgvA( i = 0; j = 0; - while ((a = CmdLine[i])) { + a = CmdLine[i]; + while (a) { if (in_QM) { if (a == '\"') { in_QM = FALSE; @@ -130,6 +131,7 @@ CommandLineToArgvA( } } i++; + a = CmdLine[i]; } _argv[j] = '\0'; argv[argc] = nullptr; diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 57f27e299fe..cf7f439aefe 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -172,18 +172,20 @@ void FileDialog::shortcut_input(const Ref &p_event) { void FileDialog::set_enable_multiple_selection(bool p_enable) { tree->set_select_mode(p_enable ? Tree::SELECT_MULTI : Tree::SELECT_SINGLE); -}; +} Vector FileDialog::get_selected_files() const { Vector list; TreeItem *item = tree->get_root(); - while ((item = tree->get_next_selected(item))) { + item = tree->get_next_selected(item); + while (item) { list.push_back(dir_access->get_current_dir().path_join(item->get_text(0))); - }; + item = tree->get_next_selected(item); + } return list; -}; +} void FileDialog::update_dir() { if (root_prefix.is_empty()) {