From 07d21b84a34068bb96fc56a52738ad1ce5233b93 Mon Sep 17 00:00:00 2001 From: Marcel Admiraal Date: Tue, 11 Feb 2020 07:53:33 +0100 Subject: Refactor List operator[] to prevent compiler warnings. Prevents GCC compiler throwing: control reaches end of non-void function. Prevents Visual Studio throwing C4715: not all control paths return a value. --- core/list.h | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/core/list.h b/core/list.h index 0796410a84..6250cec598 100644 --- a/core/list.h +++ b/core/list.h @@ -456,17 +456,12 @@ public: Element *I = front(); int c = 0; - while (I) { - - if (c == p_index) { - - return I->get(); - } + while (c < p_index) { I = I->next(); c++; } - CRASH_NOW(); // bug!! + return I->get(); } const T &operator[](int p_index) const { @@ -475,17 +470,12 @@ public: const Element *I = front(); int c = 0; - while (I) { - - if (c == p_index) { - - return I->get(); - } + while (c < p_index) { I = I->next(); c++; } - CRASH_NOW(); // bug!! + return I->get(); } void move_to_back(Element *p_I) { -- cgit v1.2.3 From a3b938d6dc9c74c3de67ad2c52f69572367a8f11 Mon Sep 17 00:00:00 2001 From: Marcel Admiraal Date: Tue, 11 Feb 2020 09:09:44 +0100 Subject: Refactor image_saver_tinyexr.cpp to prevent compiler warnings. Prevents GCC compiler throwing: control reaches end of non-void function. Prevents Visual Studio throwing C4715: not all control paths return a value. --- modules/tinyexr/image_saver_tinyexr.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/tinyexr/image_saver_tinyexr.cpp b/modules/tinyexr/image_saver_tinyexr.cpp index 17f920746f..ff97d4b85d 100644 --- a/modules/tinyexr/image_saver_tinyexr.cpp +++ b/modules/tinyexr/image_saver_tinyexr.cpp @@ -58,7 +58,8 @@ static bool is_supported_format(Image::Format p_format) { enum SrcPixelType { SRC_FLOAT, SRC_HALF, - SRC_BYTE + SRC_BYTE, + SRC_UNSUPPORTED }; static SrcPixelType get_source_pixel_type(Image::Format p_format) { @@ -79,7 +80,7 @@ static SrcPixelType get_source_pixel_type(Image::Format p_format) { case Image::FORMAT_RGBA8: return SRC_BYTE; default: - CRASH_NOW(); + return SRC_UNSUPPORTED; } } @@ -101,7 +102,7 @@ static int get_target_pixel_type(Image::Format p_format) { case Image::FORMAT_RGBA8: return TINYEXR_PIXELTYPE_HALF; default: - CRASH_NOW(); + return -1; } } @@ -112,7 +113,7 @@ static int get_pixel_type_size(int p_pixel_type) { case TINYEXR_PIXELTYPE_FLOAT: return 4; } - CRASH_NOW(); + return -1; } static int get_channel_count(Image::Format p_format) { @@ -134,7 +135,7 @@ static int get_channel_count(Image::Format p_format) { case Image::FORMAT_RGBA8: return 4; default: - CRASH_NOW(); + return -1; } } @@ -173,11 +174,15 @@ Error save_exr(const String &p_path, const Ref &p_img, bool p_grayscale) }; int channel_count = get_channel_count(format); + ERR_FAIL_COND_V(channel_count < 0, ERR_UNAVAILABLE); ERR_FAIL_COND_V(p_grayscale && channel_count != 1, ERR_INVALID_PARAMETER); int target_pixel_type = get_target_pixel_type(format); + ERR_FAIL_COND_V(target_pixel_type < 0, ERR_UNAVAILABLE); int target_pixel_type_size = get_pixel_type_size(target_pixel_type); + ERR_FAIL_COND_V(target_pixel_type_size < 0, ERR_UNAVAILABLE); SrcPixelType src_pixel_type = get_source_pixel_type(format); + ERR_FAIL_COND_V(src_pixel_type = SRC_UNSUPPORTED, ERR_UNAVAILABLE); const int pixel_count = p_img->get_width() * p_img->get_height(); const int *channel_mapping = channel_mappings[channel_count - 1]; -- cgit v1.2.3