summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-07-20 12:00:13 +0200
committerGitHub <noreply@github.com>2019-07-20 12:00:13 +0200
commitd15cf7b672ac9911b4e82fed52b4c5e8d4312b0d (patch)
tree68ab08fafd7e14710ce245a47f3bb518ebf03307 /core
parent700938bff772924941c4e1ea61bbfd2abe34d8d2 (diff)
parent6cbaf7662f5ee3ca1d02c0ebc85854fceee057af (diff)
Merge pull request #30576 from qarmin/lgtm_coverage
Changed some code reported by LGTM and Coverity
Diffstat (limited to 'core')
-rw-r--r--core/image.cpp54
-rw-r--r--core/input_map.cpp2
-rw-r--r--core/io/resource_format_binary.cpp2
-rw-r--r--core/io/resource_saver.cpp1
-rw-r--r--core/io/stream_peer.cpp4
-rw-r--r--core/math/bsp_tree.cpp4
-rw-r--r--core/math/expression.cpp6
-rw-r--r--core/pool_allocator.cpp2
-rw-r--r--core/pool_vector.h4
-rw-r--r--core/string_name.cpp3
-rw-r--r--core/variant.cpp4
-rw-r--r--core/variant_call.cpp2
-rw-r--r--core/variant_op.cpp2
-rw-r--r--core/variant_parser.cpp2
14 files changed, 38 insertions, 54 deletions
diff --git a/core/image.cpp b/core/image.cpp
index a88395204a..10778eced6 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -240,27 +240,27 @@ int Image::get_format_block_size(Format p_format) {
case FORMAT_RGTC_RG: { //bc5 case case FORMAT_DXT1:
return 4;
- } break;
+ }
case FORMAT_PVRTC2:
case FORMAT_PVRTC2A: {
return 4;
- } break;
+ }
case FORMAT_PVRTC4A:
case FORMAT_PVRTC4: {
return 4;
- } break;
+ }
case FORMAT_ETC: {
return 4;
- } break;
+ }
case FORMAT_BPTC_RGBA:
case FORMAT_BPTC_RGBF:
case FORMAT_BPTC_RGBFU: {
return 4;
- } break;
+ }
case FORMAT_ETC2_R11: //etc2
case FORMAT_ETC2_R11S: //signed: NOT srgb.
case FORMAT_ETC2_RG11:
@@ -270,7 +270,7 @@ int Image::get_format_block_size(Format p_format) {
case FORMAT_ETC2_RGB8A1: {
return 4;
- } break;
+ }
default: {
}
}
@@ -852,7 +852,7 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict
static void _overlay(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, float p_alpha, uint32_t p_width, uint32_t p_height, uint32_t p_pixel_size) {
- uint16_t alpha = CLAMP((uint16_t)(p_alpha * 256.0f), 0, 256);
+ uint16_t alpha = MIN((uint16_t)(p_alpha * 256.0f), 256);
for (uint32_t i = 0; i < p_width * p_height * p_pixel_size; i++) {
@@ -2421,38 +2421,36 @@ Color Image::get_pixel(int p_x, int p_y) const {
case FORMAT_L8: {
float l = ptr[ofs] / 255.0;
return Color(l, l, l, 1);
- } break;
+ }
case FORMAT_LA8: {
float l = ptr[ofs * 2 + 0] / 255.0;
float a = ptr[ofs * 2 + 1] / 255.0;
return Color(l, l, l, a);
- } break;
+ }
case FORMAT_R8: {
float r = ptr[ofs] / 255.0;
return Color(r, 0, 0, 1);
- } break;
+ }
case FORMAT_RG8: {
float r = ptr[ofs * 2 + 0] / 255.0;
float g = ptr[ofs * 2 + 1] / 255.0;
return Color(r, g, 0, 1);
- } break;
+ }
case FORMAT_RGB8: {
float r = ptr[ofs * 3 + 0] / 255.0;
float g = ptr[ofs * 3 + 1] / 255.0;
float b = ptr[ofs * 3 + 2] / 255.0;
return Color(r, g, b, 1);
-
- } break;
+ }
case FORMAT_RGBA8: {
float r = ptr[ofs * 4 + 0] / 255.0;
float g = ptr[ofs * 4 + 1] / 255.0;
float b = ptr[ofs * 4 + 2] / 255.0;
float a = ptr[ofs * 4 + 3] / 255.0;
return Color(r, g, b, a);
-
- } break;
+ }
case FORMAT_RGBA4444: {
uint16_t u = ((uint16_t *)ptr)[ofs];
float r = (u & 0xF) / 15.0;
@@ -2460,8 +2458,7 @@ Color Image::get_pixel(int p_x, int p_y) const {
float b = ((u >> 8) & 0xF) / 15.0;
float a = ((u >> 12) & 0xF) / 15.0;
return Color(r, g, b, a);
-
- } break;
+ }
case FORMAT_RGBA5551: {
uint16_t u = ((uint16_t *)ptr)[ofs];
@@ -2470,25 +2467,25 @@ Color Image::get_pixel(int p_x, int p_y) const {
float b = ((u >> 10) & 0x1F) / 15.0;
float a = ((u >> 15) & 0x1) / 1.0;
return Color(r, g, b, a);
- } break;
+ }
case FORMAT_RF: {
float r = ((float *)ptr)[ofs];
return Color(r, 0, 0, 1);
- } break;
+ }
case FORMAT_RGF: {
float r = ((float *)ptr)[ofs * 2 + 0];
float g = ((float *)ptr)[ofs * 2 + 1];
return Color(r, g, 0, 1);
- } break;
+ }
case FORMAT_RGBF: {
float r = ((float *)ptr)[ofs * 3 + 0];
float g = ((float *)ptr)[ofs * 3 + 1];
float b = ((float *)ptr)[ofs * 3 + 2];
return Color(r, g, b, 1);
- } break;
+ }
case FORMAT_RGBAF: {
float r = ((float *)ptr)[ofs * 4 + 0];
@@ -2496,25 +2493,25 @@ Color Image::get_pixel(int p_x, int p_y) const {
float b = ((float *)ptr)[ofs * 4 + 2];
float a = ((float *)ptr)[ofs * 4 + 3];
return Color(r, g, b, a);
- } break;
+ }
case FORMAT_RH: {
uint16_t r = ((uint16_t *)ptr)[ofs];
return Color(Math::half_to_float(r), 0, 0, 1);
- } break;
+ }
case FORMAT_RGH: {
uint16_t r = ((uint16_t *)ptr)[ofs * 2 + 0];
uint16_t g = ((uint16_t *)ptr)[ofs * 2 + 1];
return Color(Math::half_to_float(r), Math::half_to_float(g), 0, 1);
- } break;
+ }
case FORMAT_RGBH: {
uint16_t r = ((uint16_t *)ptr)[ofs * 3 + 0];
uint16_t g = ((uint16_t *)ptr)[ofs * 3 + 1];
uint16_t b = ((uint16_t *)ptr)[ofs * 3 + 2];
return Color(Math::half_to_float(r), Math::half_to_float(g), Math::half_to_float(b), 1);
- } break;
+ }
case FORMAT_RGBAH: {
uint16_t r = ((uint16_t *)ptr)[ofs * 4 + 0];
@@ -2522,18 +2519,15 @@ Color Image::get_pixel(int p_x, int p_y) const {
uint16_t b = ((uint16_t *)ptr)[ofs * 4 + 2];
uint16_t a = ((uint16_t *)ptr)[ofs * 4 + 3];
return Color(Math::half_to_float(r), Math::half_to_float(g), Math::half_to_float(b), Math::half_to_float(a));
- } break;
+ }
case FORMAT_RGBE9995: {
return Color::from_rgbe9995(((uint32_t *)ptr)[ofs]);
-
- } break;
+ }
default: {
ERR_EXPLAIN("Can't get_pixel() on compressed image, sorry.");
ERR_FAIL_V(Color());
}
}
-
- return Color();
}
void Image::set_pixelv(const Point2 &p_dst, const Color &p_color) {
diff --git a/core/input_map.cpp b/core/input_map.cpp
index 04911787a8..165999f081 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -202,7 +202,7 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
if (p_pressed != NULL)
*p_pressed = input_event_action->is_pressed();
if (p_strength != NULL)
- *p_strength = (*p_pressed) ? input_event_action->get_strength() : 0.0f;
+ *p_strength = (p_pressed != NULL && *p_pressed) ? input_event_action->get_strength() : 0.0f;
return input_event_action->get_action() == p_action;
}
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 861e34e415..38bef2768e 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -712,8 +712,8 @@ Error ResourceInteractiveLoaderBinary::poll() {
if (!obj) {
error = ERR_FILE_CORRUPT;
ERR_EXPLAIN(local_path + ":Resource of unrecognized type in file: " + t);
+ ERR_FAIL_V(ERR_FILE_CORRUPT);
}
- ERR_FAIL_COND_V(!obj, ERR_FILE_CORRUPT);
Resource *r = Object::cast_to<Resource>(obj);
if (!r) {
diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp
index 0cecca904d..e2c1c3402a 100644
--- a/core/io/resource_saver.cpp
+++ b/core/io/resource_saver.cpp
@@ -137,7 +137,6 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t
save_callback(p_resource, p_path);
return OK;
- } else {
}
}
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index acf72dbba5..84b8554d54 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -369,7 +369,9 @@ Variant StreamPeer::get_var(bool p_allow_objects) {
ERR_FAIL_COND_V(err != OK, Variant());
Variant ret;
- decode_variant(ret, var.ptr(), len, NULL, p_allow_objects);
+ err = decode_variant(ret, var.ptr(), len, NULL, p_allow_objects);
+ ERR_FAIL_COND_V(err != OK, Variant());
+
return ret;
}
diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp
index a12f9fee2e..cfa698282e 100644
--- a/core/math/bsp_tree.cpp
+++ b/core/math/bsp_tree.cpp
@@ -192,7 +192,7 @@ int BSP_Tree::get_points_inside(const Vector3 *p_points, int p_point_count) cons
#ifdef DEBUG_ENABLED
int plane_count = planes.size();
uint16_t plane = nodesptr[idx].plane;
- ERR_FAIL_INDEX_V(plane, plane_count, false);
+ ERR_FAIL_UNSIGNED_INDEX_V(plane, plane_count, false);
#endif
idx = planesptr[nodesptr[idx].plane].is_point_over(point) ? nodes[idx].over : nodes[idx].under;
@@ -258,7 +258,7 @@ bool BSP_Tree::point_is_inside(const Vector3 &p_point) const {
#ifdef DEBUG_ENABLED
int plane_count = planes.size();
uint16_t plane = nodesptr[idx].plane;
- ERR_FAIL_INDEX_V(plane, plane_count, false);
+ ERR_FAIL_UNSIGNED_INDEX_V(plane, plane_count, false);
#endif
bool over = planesptr[nodesptr[idx].plane].is_point_over(p_point);
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index 2786229cf3..25a40c70bf 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -801,17 +801,13 @@ Error Expression::_get_token(Token &r_token) {
#define GET_CHAR() (str_ofs >= expression.length() ? 0 : expression[str_ofs++])
CharType cchar = GET_CHAR();
- if (cchar == 0) {
- r_token.type = TK_EOF;
- return OK;
- }
switch (cchar) {
case 0: {
r_token.type = TK_EOF;
return OK;
- } break;
+ };
case '{': {
r_token.type = TK_CURLY_BRACKET_OPEN;
diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp
index 094352b5cc..9b342ef913 100644
--- a/core/pool_allocator.cpp
+++ b/core/pool_allocator.cpp
@@ -611,7 +611,7 @@ PoolAllocator::PoolAllocator(void *p_mem, int p_size, int p_align, bool p_needs_
PoolAllocator::PoolAllocator(int p_align, int p_size, bool p_needs_locking, int p_max_entries) {
ERR_FAIL_COND(p_align < 1);
- mem_ptr = Memory::alloc_static(p_size + p_align, "PoolAllocator()");
+ mem_ptr = Memory::alloc_static(p_size + p_align, true);
uint8_t *mem8 = (uint8_t *)mem_ptr;
uint64_t ofs = (uint64_t)mem8;
if (ofs % p_align)
diff --git a/core/pool_vector.h b/core/pool_vector.h
index 98a52c6938..3d28d86803 100644
--- a/core/pool_vector.h
+++ b/core/pool_vector.h
@@ -458,7 +458,7 @@ public:
bool is_locked() const { return alloc && alloc->lock > 0; }
- inline const T operator[](int p_index) const;
+ inline T operator[](int p_index) const;
Error resize(int p_size);
@@ -502,7 +502,7 @@ void PoolVector<T>::push_back(const T &p_val) {
}
template <class T>
-const T PoolVector<T>::operator[](int p_index) const {
+T PoolVector<T>::operator[](int p_index) const {
CRASH_BAD_INDEX(p_index, size());
diff --git a/core/string_name.cpp b/core/string_name.cpp
index 10b71ad3ac..b1a8bfb849 100644
--- a/core/string_name.cpp
+++ b/core/string_name.cpp
@@ -205,7 +205,6 @@ StringName::StringName(const char *p_name) {
// exists
lock->unlock();
return;
- } else {
}
}
@@ -253,7 +252,6 @@ StringName::StringName(const StaticCString &p_static_string) {
// exists
lock->unlock();
return;
- } else {
}
}
@@ -301,7 +299,6 @@ StringName::StringName(const String &p_name) {
// exists
lock->unlock();
return;
- } else {
}
}
diff --git a/core/variant.cpp b/core/variant.cpp
index fe9623d068..1574af5239 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -1834,8 +1834,6 @@ inline DA _convert_array_from_variant(const Variant &p_variant) {
return DA();
}
}
-
- return DA();
}
Variant::operator Array() const {
@@ -2299,7 +2297,7 @@ Variant::Variant(const Object *p_object) {
Variant::Variant(const Dictionary &p_dictionary) {
type = DICTIONARY;
- memnew_placement(_data._mem, (Dictionary)(p_dictionary));
+ memnew_placement(_data._mem, Dictionary(p_dictionary));
}
Variant::Variant(const Array &p_array) {
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 3fdd18a630..b637e745af 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -70,7 +70,7 @@ struct _VariantCall {
for (int i = 0; i < arg_count; i++) {
- if (!tptr[i] || tptr[i] == p_args[i]->type)
+ if (tptr[i] == Variant::NIL || tptr[i] == p_args[i]->type)
continue; // all good
if (!Variant::can_convert(p_args[i]->type, tptr[i])) {
r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index d677c7776a..ea9e29e744 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -2613,7 +2613,7 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (r_valid) {
*r_valid = false;
}
- return "Attempted get on stray pointer.";
+ return true; // Attempted get on stray pointer.
}
}
#endif
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index d5513bc2d7..07212ec669 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -1537,8 +1537,6 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r
Token token;
get_token(p_stream, token, line, r_err_str);
Error err = parse_value(token, r_value, p_stream, line, r_err_str, p_res_parser);
- if (err) {
- }
return err;
}
} else if (c == '\n') {