Browse Source

Small fixes to static analyzer bugs

qarmin 6 years ago
parent
commit
8460d0678c

+ 2 - 4
core/list.h

@@ -503,8 +503,7 @@ public:
 		if (p_I->prev_ptr)
 			p_I->prev_ptr->next_ptr = p_I->next_ptr;
 
-		if (p_I->next_ptr)
-			p_I->next_ptr->prev_ptr = p_I->prev_ptr;
+		p_I->next_ptr->prev_ptr = p_I->prev_ptr;
 
 		_data->last->next_ptr = p_I;
 		p_I->prev_ptr = _data->last;
@@ -538,8 +537,7 @@ public:
 		if (_data->last == p_I)
 			_data->last = p_I->prev_ptr;
 
-		if (p_I->prev_ptr)
-			p_I->prev_ptr->next_ptr = p_I->next_ptr;
+		p_I->prev_ptr->next_ptr = p_I->next_ptr;
 
 		if (p_I->next_ptr)
 			p_I->next_ptr->prev_ptr = p_I->prev_ptr;

+ 1 - 1
core/math/rect2.h

@@ -67,7 +67,7 @@ struct Rect2 {
 
 		if (p_point.x < position.x) {
 			real_t d = position.x - p_point.x;
-			dist = inside ? d : MIN(dist, d);
+			dist = d;
 			inside = false;
 		}
 		if (p_point.y < position.y) {

+ 6 - 6
editor/plugins/animation_player_editor_plugin.cpp

@@ -841,6 +841,12 @@ void AnimationPlayerEditor::_update_player() {
 	onion_skinning->set_disabled(player == NULL);
 	pin->set_disabled(player == NULL);
 
+	if (!player) {
+		AnimationPlayerEditor::singleton->get_track_editor()->update_keying();
+		EditorNode::get_singleton()->update_keying();
+		return;
+	}
+
 	int active_idx = -1;
 	for (List<StringName>::Element *E = animlist.front(); E; E = E->next()) {
 
@@ -853,12 +859,6 @@ void AnimationPlayerEditor::_update_player() {
 			active_idx = animation->get_item_count() - 1;
 	}
 
-	if (!player) {
-		AnimationPlayerEditor::singleton->get_track_editor()->update_keying();
-		EditorNode::get_singleton()->update_keying();
-		return;
-	}
-
 	updating = false;
 	if (active_idx != -1) {
 		animation->select(active_idx);

+ 8 - 4
editor/plugins/canvas_item_editor_plugin.cpp

@@ -1462,10 +1462,14 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref<InputEvent> &p_event) {
 					if (!use_single_axis || use_y) control->set_anchor(MARGIN_BOTTOM, new_anchor.y, false, false);
 					break;
 				case DRAG_ANCHOR_ALL:
-					if (!use_single_axis || !use_y) control->set_anchor(MARGIN_LEFT, new_anchor.x, false, true);
-					if (!use_single_axis || !use_y) control->set_anchor(MARGIN_RIGHT, new_anchor.x, false, true);
-					if (!use_single_axis || use_y) control->set_anchor(MARGIN_TOP, new_anchor.y, false, true);
-					if (!use_single_axis || use_y) control->set_anchor(MARGIN_BOTTOM, new_anchor.y, false, true);
+					if (!use_single_axis || !use_y) {
+						control->set_anchor(MARGIN_LEFT, new_anchor.x, false, true);
+						control->set_anchor(MARGIN_RIGHT, new_anchor.x, false, true);
+					}
+					if (!use_single_axis || use_y) {
+						control->set_anchor(MARGIN_TOP, new_anchor.y, false, true);
+						control->set_anchor(MARGIN_BOTTOM, new_anchor.y, false, true);
+					}
 					break;
 				default:
 					break;

+ 3 - 2
modules/gdscript/gdscript.h

@@ -406,9 +406,10 @@ public:
 		csi.resize(_debug_call_stack_pos);
 		for (int i = 0; i < _debug_call_stack_pos; i++) {
 			csi.write[_debug_call_stack_pos - i - 1].line = _call_stack[i].line ? *_call_stack[i].line : 0;
-			if (_call_stack[i].function)
+			if (_call_stack[i].function) {
 				csi.write[_debug_call_stack_pos - i - 1].func = _call_stack[i].function->get_name();
-			csi.write[_debug_call_stack_pos - i - 1].file = _call_stack[i].function->get_script()->get_path();
+				csi.write[_debug_call_stack_pos - i - 1].file = _call_stack[i].function->get_script()->get_path();
+			}
 		}
 		return csi;
 	}

+ 4 - 7
modules/gdscript/gdscript_editor.cpp

@@ -2165,7 +2165,6 @@ static void _find_identifiers(const GDScriptCompletionContext &p_context, bool p
 static void _find_call_arguments(const GDScriptCompletionContext &p_context, const GDScriptCompletionIdentifier &p_base, const StringName &p_method, int p_argidx, bool p_static, Set<String> &r_result, String &r_arghint) {
 	Variant base = p_base.value;
 	GDScriptParser::DataType base_type = p_base.type;
-	bool _static = false;
 
 	while (base_type.has_type) {
 		switch (base_type.kind) {
@@ -2176,12 +2175,10 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con
 						return;
 					}
 				}
-				if (!_static) {
-					for (int i = 0; i < base_type.class_type->functions.size(); i++) {
-						if (base_type.class_type->functions[i]->name == p_method) {
-							r_arghint = _make_arguments_hint(base_type.class_type->functions[i], p_argidx);
-							return;
-						}
+				for (int i = 0; i < base_type.class_type->functions.size(); i++) {
+					if (base_type.class_type->functions[i]->name == p_method) {
+						r_arghint = _make_arguments_hint(base_type.class_type->functions[i], p_argidx);
+						return;
 					}
 				}
 

+ 4 - 9
modules/gdscript/gdscript_parser.cpp

@@ -282,7 +282,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
 
 				switch (tokenizer->get_token()) {
 					case GDScriptTokenizer::TK_CURSOR: {
-						completion_cursor = StringName();
 						completion_type = COMPLETION_GET_NODE;
 						completion_class = current_class;
 						completion_function = current_function;
@@ -2864,8 +2863,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
 				lv->assign_op = op;
 				lv->assign = assigned;
 
-				lv->assign_op = op;
-
 				if (!_end_statement()) {
 					_set_error("Expected end of statement (var)");
 					return;
@@ -6179,8 +6176,8 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
 						return DataType();
 					}
 #ifdef DEBUG_ENABLED
-					if (var_op == Variant::OP_DIVIDE && argument_a_type.has_type && argument_a_type.kind == DataType::BUILTIN && argument_a_type.builtin_type == Variant::INT &&
-							argument_b_type.has_type && argument_b_type.kind == DataType::BUILTIN && argument_b_type.builtin_type == Variant::INT) {
+					if (var_op == Variant::OP_DIVIDE && argument_a_type.kind == DataType::BUILTIN && argument_a_type.builtin_type == Variant::INT &&
+							argument_b_type.kind == DataType::BUILTIN && argument_b_type.builtin_type == Variant::INT) {
 						_add_warning(GDScriptWarning::INTEGER_DIVISION, op->line);
 					}
 #endif // DEBUG_ENABLED
@@ -6889,10 +6886,8 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat
 
 #ifdef DEBUG_ENABLED
 			if (current_function && !for_completion && !is_static && p_call->arguments[0]->type == Node::TYPE_SELF && current_function->_static) {
-				if (current_function && current_function->_static && p_call->arguments[0]->type == Node::TYPE_SELF) {
-					_set_error("Can't call non-static function from a static function.", p_call->line);
-					return DataType();
-				}
+				_set_error("Can't call non-static function from a static function.", p_call->line);
+				return DataType();
 			}
 
 			if (check_types && !is_static && !is_initializer && base_type.is_meta_type) {

+ 0 - 2
platform/android/export/export.cpp

@@ -1515,7 +1515,6 @@ public:
 			return ERR_FILE_NOT_FOUND;
 		}
 
-		ERR_FAIL_COND_V(!pkg, ERR_CANT_OPEN);
 		int ret = unzGoToFirstFile(pkg);
 
 		zlib_filefunc_def io2 = io;
@@ -1855,7 +1854,6 @@ public:
 			return ERR_FILE_NOT_FOUND;
 		}
 
-		ERR_FAIL_COND_V(!tmp_unaligned, ERR_CANT_OPEN);
 		ret = unzGoToFirstFile(tmp_unaligned);
 
 		io2 = io;

+ 1 - 1
platform/iphone/export/export.cpp

@@ -920,7 +920,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
 		EditorNode::add_io_error("Could not open export template (not a zip file?):\n" + src_pkg_name);
 		return ERR_CANT_OPEN;
 	}
-	ERR_FAIL_COND_V(!src_pkg_zip, ERR_CANT_OPEN);
+
 	int ret = unzGoToFirstFile(src_pkg_zip);
 	Vector<uint8_t> project_file_data;
 	while (ret == UNZ_OK) {

+ 0 - 1
platform/osx/export/export.cpp

@@ -441,7 +441,6 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
 		return ERR_FILE_NOT_FOUND;
 	}
 
-	ERR_FAIL_COND_V(!src_pkg_zip, ERR_CANT_OPEN);
 	int ret = unzGoToFirstFile(src_pkg_zip);
 
 	String binary_to_use = "godot_osx_" + String(p_debug ? "debug" : "release") + ".64";

+ 4 - 6
platform/x11/crash_handler_x11.cpp

@@ -96,12 +96,10 @@ static void handle_crash(int sig) {
 			String output = "";
 
 			// Try to get the file/line number using addr2line
-			if (OS::get_singleton()) {
-				int ret;
-				Error err = OS::get_singleton()->execute(String("addr2line"), args, true, NULL, &output, &ret);
-				if (err == OK) {
-					output.erase(output.length() - 1, 1);
-				}
+			int ret;
+			Error err = OS::get_singleton()->execute(String("addr2line"), args, true, NULL, &output, &ret);
+			if (err == OK) {
+				output.erase(output.length() - 1, 1);
 			}
 
 			fprintf(stderr, "[%ld] %s (%ls)\n", i, fname, output.c_str());

+ 26 - 28
platform/x11/os_x11.cpp

@@ -503,35 +503,33 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
 
 	current_cursor = CURSOR_ARROW;
 
-	if (cursor_theme) {
-		for (int i = 0; i < CURSOR_MAX; i++) {
-
-			static const char *cursor_file[] = {
-				"left_ptr",
-				"xterm",
-				"hand2",
-				"cross",
-				"watch",
-				"left_ptr_watch",
-				"fleur",
-				"hand1",
-				"X_cursor",
-				"sb_v_double_arrow",
-				"sb_h_double_arrow",
-				"size_bdiag",
-				"size_fdiag",
-				"hand1",
-				"sb_v_double_arrow",
-				"sb_h_double_arrow",
-				"question_arrow"
-			};
+	for (int i = 0; i < CURSOR_MAX; i++) {
 
-			img[i] = XcursorLibraryLoadImage(cursor_file[i], cursor_theme, cursor_size);
-			if (img[i]) {
-				cursors[i] = XcursorImageLoadCursor(x11_display, img[i]);
-			} else {
-				print_verbose("Failed loading custom cursor: " + String(cursor_file[i]));
-			}
+		static const char *cursor_file[] = {
+			"left_ptr",
+			"xterm",
+			"hand2",
+			"cross",
+			"watch",
+			"left_ptr_watch",
+			"fleur",
+			"hand1",
+			"X_cursor",
+			"sb_v_double_arrow",
+			"sb_h_double_arrow",
+			"size_bdiag",
+			"size_fdiag",
+			"hand1",
+			"sb_v_double_arrow",
+			"sb_h_double_arrow",
+			"question_arrow"
+		};
+
+		img[i] = XcursorLibraryLoadImage(cursor_file[i], cursor_theme, cursor_size);
+		if (img[i]) {
+			cursors[i] = XcursorImageLoadCursor(x11_display, img[i]);
+		} else {
+			print_verbose("Failed loading custom cursor: " + String(cursor_file[i]));
 		}
 	}
 

+ 1 - 1
platform/x11/power_x11.cpp

@@ -115,7 +115,7 @@ bool PowerX11::make_proc_acpi_key_val(char **_ptr, char **_key, char **_val) {
 
 	*(ptr++) = '\0'; /* terminate the key. */
 
-	while ((*ptr == ' ') && (*ptr != '\0')) {
+	while (*ptr == ' ') {
 		ptr++; /* skip whitespace. */
 	}
 

+ 0 - 1
scene/resources/animation.h

@@ -93,7 +93,6 @@ private:
 	template <class T>
 	struct TKey : public Key {
 
-		float time;
 		T value;
 	};