Fixes minor issues found by static analyzer

This commit is contained in:
qarmin 2019-07-07 23:08:51 +02:00
parent d897131ac5
commit 9a77d748c0
26 changed files with 39 additions and 45 deletions

2
.gitignore vendored
View file

@ -343,3 +343,5 @@ platform/windows/godot_res.res
# compile commands (https://clang.llvm.org/docs/JSONCompilationDatabase.html)
compile_commands.json
# Cppcheck
*.cppcheck

View file

@ -778,7 +778,7 @@ Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p
if (p_allow_empty || (end > from)) {
if (p_maxsplit <= 0)
ret.push_back(substr(from, end - from));
else if (p_maxsplit > 0) {
else {
// Put rest of the string and leave cycle.
if (p_maxsplit == ret.size()) {

View file

@ -2526,19 +2526,19 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
int v = value;
GLuint *gui = (GLuint *)data;
gui[0] = v & 1 ? GL_TRUE : GL_FALSE;
gui[1] = v & 2 ? GL_TRUE : GL_FALSE;
gui[2] = v & 4 ? GL_TRUE : GL_FALSE;
gui[0] = (v & 1) ? GL_TRUE : GL_FALSE;
gui[1] = (v & 2) ? GL_TRUE : GL_FALSE;
gui[2] = (v & 4) ? GL_TRUE : GL_FALSE;
} break;
case ShaderLanguage::TYPE_BVEC4: {
int v = value;
GLuint *gui = (GLuint *)data;
gui[0] = v & 1 ? GL_TRUE : GL_FALSE;
gui[1] = v & 2 ? GL_TRUE : GL_FALSE;
gui[2] = v & 4 ? GL_TRUE : GL_FALSE;
gui[3] = v & 8 ? GL_TRUE : GL_FALSE;
gui[0] = (v & 1) ? GL_TRUE : GL_FALSE;
gui[1] = (v & 2) ? GL_TRUE : GL_FALSE;
gui[2] = (v & 4) ? GL_TRUE : GL_FALSE;
gui[3] = (v & 8) ? GL_TRUE : GL_FALSE;
} break;
case ShaderLanguage::TYPE_INT: {
@ -3441,7 +3441,7 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh, uint32_t p_format, VS:
glGenBuffers(1, &surface->vertex_id);
glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id);
glBufferData(GL_ARRAY_BUFFER, array_size, vr.ptr(), p_format & VS::ARRAY_FLAG_USE_DYNAMIC_UPDATE ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, array_size, vr.ptr(), (p_format & VS::ARRAY_FLAG_USE_DYNAMIC_UPDATE) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
if (p_format & VS::ARRAY_FORMAT_INDEX) {

View file

@ -256,7 +256,7 @@ OS::TimeZoneInfo OS_Unix::get_time_zone_info() const {
void OS_Unix::delay_usec(uint32_t p_usec) const {
struct timespec rem = { static_cast<time_t>(p_usec / 1000000), static_cast<long>((p_usec % 1000000) * 1000) };
struct timespec rem = { static_cast<time_t>(p_usec / 1000000), (static_cast<long>(p_usec) % 1000000) * 1000 };
while (nanosleep(&rem, &rem) == EINTR) {
}
}

View file

@ -210,13 +210,13 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p
if (is_subsequence_of_type && !is_selected_equal) {
if (is_substring_of_type) {
if (!is_substring_of_selected || (is_substring_of_selected && (current_type_prefered && !selected_type_prefered))) {
if (!is_substring_of_selected || (current_type_prefered && !selected_type_prefered)) {
*to_select = item;
}
} else {
// substring results weigh more than subsequences, so let's make sure we don't override them
if (!is_substring_of_selected) {
if (!is_subsequence_of_selected || (is_subsequence_of_selected && (current_type_prefered && !selected_type_prefered))) {
if (!is_subsequence_of_selected || (current_type_prefered && !selected_type_prefered)) {
*to_select = item;
}
}

View file

@ -337,7 +337,7 @@ bool EditorHelpSearch::Runner::_phase_match_classes() {
if (term.length() > 1) {
if (search_flags & SEARCH_METHODS)
for (int i = 0; i < class_doc.methods.size(); i++) {
String method_name = search_flags & SEARCH_CASE_SENSITIVE ? class_doc.methods[i].name : class_doc.methods[i].name.to_lower();
String method_name = (search_flags & SEARCH_CASE_SENSITIVE) ? class_doc.methods[i].name : class_doc.methods[i].name.to_lower();
if (method_name.find(term) > -1 ||
(term.begins_with(".") && method_name.begins_with(term.right(1))) ||
(term.ends_with("(") && method_name.ends_with(term.left(term.length() - 1).strip_edges())) ||
@ -405,7 +405,7 @@ bool EditorHelpSearch::Runner::_phase_member_items() {
ClassMatch &match = iterator_match->value();
TreeItem *parent = search_flags & SEARCH_SHOW_HIERARCHY ? class_items[match.doc->name] : root_item;
TreeItem *parent = (search_flags & SEARCH_SHOW_HIERARCHY) ? class_items[match.doc->name] : root_item;
for (int i = 0; i < match.methods.size(); i++)
_create_method_item(parent, match.doc, match.methods[i]);
for (int i = 0; i < match.signals.size(); i++)

View file

@ -6048,7 +6048,6 @@ void EditorSpatialGizmoPlugin::create_icon_material(const String &p_name, const
void EditorSpatialGizmoPlugin::create_handle_material(const String &p_name, bool p_billboard) {
Ref<SpatialMaterial> handle_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
handle_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
handle_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
handle_material->set_flag(SpatialMaterial::FLAG_USE_POINT_SIZE, true);
Ref<Texture> handle_t = SpatialEditor::get_singleton()->get_icon("Editor3DHandle", "EditorIcons");

View file

@ -873,7 +873,7 @@ void InputDefault::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
return;
}
float deadzone = p_value.min == 0 ? 0.5f : 0.0f;
bool pressed = p_value.value > deadzone ? true : false;
bool pressed = p_value.value > deadzone;
if (pressed == joy_buttons_pressed.has(_combine_device(map.index, p_device))) {
// button already pressed or released, this is an axis bounce value
return;

View file

@ -854,7 +854,7 @@ Ref<Material> EditorSceneImporterAssimp::_generate_material_from_index(ImportSta
if (found) {
Ref<Texture> texture = _load_texture(state, path);
if (texture != NULL) {
if (texture.is_valid()) {
_set_texture_mapping_mode(map_mode, texture);
mat->set_feature(SpatialMaterial::Feature::FEATURE_NORMAL_MAPPING, true);
mat->set_texture(SpatialMaterial::TEXTURE_NORMAL, texture);

View file

@ -728,12 +728,12 @@ bool RigidBodyBullet::is_axis_locked(PhysicsServer::BodyAxis p_axis) const {
void RigidBodyBullet::reload_axis_lock() {
btBody->setLinearFactor(btVector3(!is_axis_locked(PhysicsServer::BODY_AXIS_LINEAR_X), !is_axis_locked(PhysicsServer::BODY_AXIS_LINEAR_Y), !is_axis_locked(PhysicsServer::BODY_AXIS_LINEAR_Z)));
btBody->setLinearFactor(btVector3(float(!is_axis_locked(PhysicsServer::BODY_AXIS_LINEAR_X)), float(!is_axis_locked(PhysicsServer::BODY_AXIS_LINEAR_Y)), float(!is_axis_locked(PhysicsServer::BODY_AXIS_LINEAR_Z))));
if (PhysicsServer::BODY_MODE_CHARACTER == mode) {
/// When character angular is always locked
btBody->setAngularFactor(btVector3(0., 0., 0.));
} else {
btBody->setAngularFactor(btVector3(!is_axis_locked(PhysicsServer::BODY_AXIS_ANGULAR_X), !is_axis_locked(PhysicsServer::BODY_AXIS_ANGULAR_Y), !is_axis_locked(PhysicsServer::BODY_AXIS_ANGULAR_Z)));
btBody->setAngularFactor(btVector3(float(!is_axis_locked(PhysicsServer::BODY_AXIS_ANGULAR_X)), float(!is_axis_locked(PhysicsServer::BODY_AXIS_ANGULAR_Y)), float(!is_axis_locked(PhysicsServer::BODY_AXIS_ANGULAR_Z))));
}
}

View file

@ -578,7 +578,7 @@ void GridMapEditor::_update_paste_indicator() {
return;
}
Vector3 center = 0.5 * Vector3(node->get_center_x(), node->get_center_y(), node->get_center_z());
Vector3 center = 0.5 * Vector3(float(node->get_center_x()), float(node->get_center_y()), float(node->get_center_z()));
Vector3 scale = (Vector3(1, 1, 1) + (paste_indicator.end - paste_indicator.begin)) * node->get_cell_size();
Transform xf;
xf.scale(scale);

View file

@ -44,7 +44,7 @@ int sfind(const String &p_text, int p_from) {
int src_len = 2;
int len = p_text.length();
if (src_len == 0 || len == 0)
if (len == 0)
return -1;
const CharType *src = p_text.c_str();

View file

@ -280,7 +280,7 @@ int AudioStreamPlaybackOpus::mix(int16_t *p_buffer, int p_frames) {
int todo = p_frames;
if (todo == 0 || todo < MIN_MIX) {
if (todo < MIN_MIX) {
break;
}

View file

@ -1487,7 +1487,7 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p
Variant **output_args = (Variant **)(input_args + max_input_args);
int flow_max = f->flow_stack_size;
int *flow_stack = flow_max ? (int *)(output_args + max_output_args) : (int *)NULL;
int *pass_stack = flow_stack + flow_max;
int *pass_stack = flow_stack ? (int *)(flow_stack + flow_max) : (int *)NULL;
String error_str;
@ -1905,7 +1905,7 @@ Variant VisualScriptInstance::call(const StringName &p_method, const Variant **p
Variant **output_args = (Variant **)(input_args + max_input_args);
int flow_max = f->flow_stack_size;
int *flow_stack = flow_max ? (int *)(output_args + max_output_args) : (int *)NULL;
int *pass_stack = flow_stack + flow_max;
int *pass_stack = flow_stack ? (int *)(flow_stack + flow_max) : (int *)NULL;
for (int i = 0; i < f->node_count; i++) {
sequence_bits[i] = false; //all starts as false

View file

@ -570,7 +570,6 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const
Node *bnode = _get_base_node();
if (bnode) {
property.hint_string = bnode->get_path(); //convert to loong string
} else {
}
}
}
@ -1035,8 +1034,6 @@ PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const
pi.name = (call_mode == CALL_MODE_INSTANCE ? String("instance") : Variant::get_type_name(basic_type).to_lower());
_adjust_input_index(pi);
return pi;
} else {
p_idx--;
}
}
@ -1352,7 +1349,6 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const {
Node *bnode = _get_base_node();
if (bnode) {
property.hint_string = bnode->get_path(); //convert to loong string
} else {
}
}
}
@ -1794,8 +1790,6 @@ PropertyInfo VisualScriptPropertyGet::get_input_value_port_info(int p_idx) const
pi.type = (call_mode == CALL_MODE_INSTANCE ? Variant::OBJECT : basic_type);
pi.name = (call_mode == CALL_MODE_INSTANCE ? String("instance") : Variant::get_type_name(basic_type).to_lower());
return pi;
} else {
p_idx--;
}
}
return PropertyInfo();
@ -2073,7 +2067,6 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const {
Node *bnode = _get_base_node();
if (bnode) {
property.hint_string = bnode->get_path(); //convert to loong string
} else {
}
}
}

View file

@ -431,7 +431,6 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const {
Node *bnode = _get_base_node();
if (bnode) {
property.hint_string = bnode->get_path(); //convert to loong string
} else {
}
}
}

View file

@ -103,7 +103,7 @@ int AudioStreamPlaybackOGGVorbis::mix(int16_t *p_buffer, int p_frames) {
int todo = p_frames;
if (todo == 0 || todo < MIN_MIX) {
if (todo < MIN_MIX) {
break;
}

View file

@ -191,7 +191,7 @@ void WebSocketMultiplayerPeer::_send_sys(Ref<WebSocketPeer> p_peer, uint8_t p_ty
p_peer->put_packet(&(message.read()[0]), message.size());
}
PoolVector<uint8_t> WebSocketMultiplayerPeer::_make_pkt(uint32_t p_type, int32_t p_from, int32_t p_to, const uint8_t *p_data, uint32_t p_data_size) {
PoolVector<uint8_t> WebSocketMultiplayerPeer::_make_pkt(uint8_t p_type, int32_t p_from, int32_t p_to, const uint8_t *p_data, uint32_t p_data_size) {
PoolVector<uint8_t> out;
out.resize(PROTO_SIZE + p_data_size);

View file

@ -41,7 +41,7 @@ class WebSocketMultiplayerPeer : public NetworkedMultiplayerPeer {
GDCLASS(WebSocketMultiplayerPeer, NetworkedMultiplayerPeer);
private:
PoolVector<uint8_t> _make_pkt(uint32_t p_type, int32_t p_from, int32_t p_to, const uint8_t *p_data, uint32_t p_data_size);
PoolVector<uint8_t> _make_pkt(uint8_t p_type, int32_t p_from, int32_t p_to, const uint8_t *p_data, uint32_t p_data_size);
void _store_pkt(int32_t p_source, int32_t p_dest, const uint8_t *p_data, uint32_t p_data_size);
Error _server_relay(int32_t p_from, int32_t p_to, const uint8_t *p_buffer, uint32_t p_buffer_size);

View file

@ -62,7 +62,7 @@ Error FileAccessJAndroid::_open(const String &p_path, int p_mode_flags) {
JNIEnv *env = ThreadAndroid::get_env();
jstring js = env->NewStringUTF(path.utf8().get_data());
int res = env->CallIntMethod(io, _file_open, js, p_mode_flags & WRITE ? true : false);
int res = env->CallIntMethod(io, _file_open, js, (p_mode_flags & WRITE) ? true : false);
env->DeleteLocalRef(js);
OS::get_singleton()->print("fopen: '%s' ret %i\n", path.utf8().get_data(), res);

View file

@ -43,6 +43,7 @@ int main(int argc, char *argv[]) {
setlocale(LC_CTYPE, "");
char *cwd = (char *)malloc(PATH_MAX);
ERR_FAIL_COND_V(!cwd, ERR_OUT_OF_MEMORY);
char *ret = getcwd(cwd, PATH_MAX);
Error err = Main::setup(argv[0], argc - 1, &argv[1]);

View file

@ -179,7 +179,7 @@ public:
void set_extents(const Vector3 &p_extents);
Vector3 get_extents() const;
void set_bake_default_texels_per_unit(const float &p_extents);
void set_bake_default_texels_per_unit(const float &p_bake_texels_per_unit);
float get_bake_default_texels_per_unit() const;
void set_propagation(float p_propagation);

View file

@ -257,7 +257,7 @@ String Particles::get_configuration_warning() const {
SpatialMaterial *spat = Object::cast_to<SpatialMaterial>(draw_passes[i]->surface_get_material(j).ptr());
anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == SpatialMaterial::BILLBOARD_PARTICLES);
}
if (meshes_found && anim_material_found) break;
if (anim_material_found) break;
}
}

View file

@ -1191,7 +1191,7 @@ void LineEdit::set_cursor_position(int p_pos) {
if (cursor_pos <= window_pos) {
/* Adjust window if cursor goes too much to the left */
set_window_pos(MAX(0, cursor_pos - 1));
} else if (cursor_pos > window_pos) {
} else {
/* Adjust window if cursor goes too much to the right */
int window_width = get_size().width - style->get_minimum_size().width;
bool display_clear_icon = !text.empty() && is_editable() && clear_button_enabled;

View file

@ -1815,7 +1815,7 @@ T Animation::_interpolate(const Vector<TKey<T> > &p_keys, float p_time, Interpol
next = idx;
}
} else if (idx < 0) {
} else {
// only allow extending first key to anim start if looping
if (loop)

View file

@ -87,11 +87,11 @@ real_t ARVRServer::get_world_scale() const {
};
void ARVRServer::set_world_scale(real_t p_world_scale) {
if (world_scale < 0.01) {
world_scale = 0.01;
} else if (world_scale > 1000.0) {
world_scale = 1000.0;
};
if (p_world_scale < 0.01) {
p_world_scale = 0.01;
} else if (p_world_scale > 1000.0) {
p_world_scale = 1000.0;
}
world_scale = p_world_scale;
};