Small fixes to unrechable code, possibly overflows, using NULL pointers

This commit is contained in:
qarmin 2019-06-03 21:52:50 +02:00
parent 8c923fc617
commit 8245db869f
18 changed files with 48 additions and 70 deletions

View file

@ -162,20 +162,21 @@ private:
new_hash_table[i] = 0; new_hash_table[i] = 0;
} }
for (int i = 0; i < (1 << hash_table_power); i++) { if (hash_table) {
for (int i = 0; i < (1 << hash_table_power); i++) {
while (hash_table[i]) { while (hash_table[i]) {
Element *se = hash_table[i]; Element *se = hash_table[i];
hash_table[i] = se->next; hash_table[i] = se->next;
int new_pos = se->hash & ((1 << new_hash_table_power) - 1); int new_pos = se->hash & ((1 << new_hash_table_power) - 1);
se->next = new_hash_table[new_pos]; se->next = new_hash_table[new_pos];
new_hash_table[new_pos] = se; new_hash_table[new_pos] = se;
}
} }
}
if (hash_table)
memdelete_arr(hash_table); memdelete_arr(hash_table);
}
hash_table = new_hash_table; hash_table = new_hash_table;
hash_table_power = new_hash_table_power; hash_table_power = new_hash_table_power;
} }

View file

@ -198,10 +198,6 @@ Error ConfigFile::load(const String &p_path) {
section = next_tag.name; section = next_tag.name;
} }
} }
memdelete(f);
return OK;
} }
void ConfigFile::_bind_methods() { void ConfigFile::_bind_methods() {

View file

@ -571,10 +571,6 @@ Error ProjectSettings::_load_settings_text(const String p_path) {
section = next_tag.name; section = next_tag.name;
} }
} }
memdelete(f);
return OK;
} }
Error ProjectSettings::_load_settings_text_or_binary(const String p_text_path, const String p_bin_path) { Error ProjectSettings::_load_settings_text_or_binary(const String p_text_path, const String p_bin_path) {

View file

@ -2956,26 +2956,12 @@ String String::replace(const char *p_key, const char *p_with) const {
String String::replace_first(const String &p_key, const String &p_with) const { String String::replace_first(const String &p_key, const String &p_with) const {
String new_string; int pos = find(p_key);
int search_from = 0; if (pos >= 0) {
int result = 0; return substr(0, pos) + p_with + substr(pos + p_key.length(), length());
while ((result = find(p_key, search_from)) >= 0) {
new_string += substr(search_from, result - search_from);
new_string += p_with;
search_from = result + p_key.length();
break;
} }
if (search_from == 0) { return *this;
return *this;
}
new_string += substr(search_from, length() - search_from);
return new_string;
} }
String String::replacen(const String &p_key, const String &p_with) const { String String::replacen(const String &p_key, const String &p_with) const {

View file

@ -2244,7 +2244,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
bool rebind_reflection = false; bool rebind_reflection = false;
bool rebind_lightmap = false; bool rebind_lightmap = false;
if (!p_shadow) { if (!p_shadow && material->shader) {
bool unshaded = material->shader->spatial.unshaded; bool unshaded = material->shader->spatial.unshaded;
@ -2264,7 +2264,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
bool depth_prepass = false; bool depth_prepass = false;
if (!p_alpha_pass && material->shader && material->shader->spatial.depth_draw_mode == RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) { if (!p_alpha_pass && material->shader->spatial.depth_draw_mode == RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) {
depth_prepass = true; depth_prepass = true;
} }
@ -2900,7 +2900,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
if (storage->frame.current_rt && state.used_screen_texture) { if (storage->frame.current_rt && state.used_screen_texture) {
//copy screen texture //copy screen texture
if (storage->frame.current_rt && storage->frame.current_rt->multisample_active) { if (storage->frame.current_rt->multisample_active) {
// Resolve framebuffer to front buffer before copying // Resolve framebuffer to front buffer before copying
#ifdef GLES_OVER_GL #ifdef GLES_OVER_GL

View file

@ -4552,8 +4552,8 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
} }
_post_process(env, p_cam_projection); _post_process(env, p_cam_projection);
// Needed only for debugging
if (false && shadow_atlas) { /* if (shadow_atlas && storage->frame.current_rt) {
//_copy_texture_to_front_buffer(shadow_atlas->depth); //_copy_texture_to_front_buffer(shadow_atlas->depth);
storage->canvas->canvas_begin(); storage->canvas->canvas_begin();
@ -4563,7 +4563,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 2, storage->frame.current_rt->height / 2), Rect2(0, 0, 1, 1)); storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 2, storage->frame.current_rt->height / 2), Rect2(0, 0, 1, 1));
} }
if (false && storage->frame.current_rt) { if (storage->frame.current_rt) {
//_copy_texture_to_front_buffer(shadow_atlas->depth); //_copy_texture_to_front_buffer(shadow_atlas->depth);
storage->canvas->canvas_begin(); storage->canvas->canvas_begin();
@ -4573,7 +4573,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 16, storage->frame.current_rt->height / 16), Rect2(0, 0, 1, 1)); storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 16, storage->frame.current_rt->height / 16), Rect2(0, 0, 1, 1));
} }
if (false && reflection_atlas && storage->frame.current_rt) { if (reflection_atlas && storage->frame.current_rt) {
//_copy_texture_to_front_buffer(shadow_atlas->depth); //_copy_texture_to_front_buffer(shadow_atlas->depth);
storage->canvas->canvas_begin(); storage->canvas->canvas_begin();
@ -4582,7 +4582,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 2, storage->frame.current_rt->height / 2), Rect2(0, 0, 1, 1)); storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 2, storage->frame.current_rt->height / 2), Rect2(0, 0, 1, 1));
} }
if (false && directional_shadow.fbo) { if (directional_shadow.fbo) {
//_copy_texture_to_front_buffer(shadow_atlas->depth); //_copy_texture_to_front_buffer(shadow_atlas->depth);
storage->canvas->canvas_begin(); storage->canvas->canvas_begin();
@ -4592,7 +4592,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 2, storage->frame.current_rt->height / 2), Rect2(0, 0, 1, 1)); storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 2, storage->frame.current_rt->height / 2), Rect2(0, 0, 1, 1));
} }
if (false && env_radiance_tex) { if ( env_radiance_tex) {
//_copy_texture_to_front_buffer(shadow_atlas->depth); //_copy_texture_to_front_buffer(shadow_atlas->depth);
storage->canvas->canvas_begin(); storage->canvas->canvas_begin();
@ -4603,8 +4603,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 2, storage->frame.current_rt->height / 2), Rect2(0, 0, 1, 1)); storage->canvas->draw_generic_textured_rect(Rect2(0, 0, storage->frame.current_rt->width / 2, storage->frame.current_rt->height / 2), Rect2(0, 0, 1, 1));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} }*/
//disable all stuff //disable all stuff
} }

View file

@ -129,7 +129,7 @@ void AudioStreamPreviewGenerator::_preview_thread(void *p_preview) {
float max = -1000; float max = -1000;
float min = 1000; float min = 1000;
int from = uint64_t(i) * to_read / to_write; int from = uint64_t(i) * to_read / to_write;
int to = uint64_t(i + 1) * to_read / to_write; int to = (uint64_t(i) + 1) * to_read / to_write;
to = MIN(to, to_read); to = MIN(to, to_read);
from = MIN(from, to_read - 1); from = MIN(from, to_read - 1);
if (to == from) { if (to == from) {

View file

@ -912,7 +912,7 @@ void CodeTextEditor::convert_case(CaseStyle p_case) {
for (int i = begin; i <= end; i++) { for (int i = begin; i <= end; i++) {
int len = text_editor->get_line(i).length(); int len = text_editor->get_line(i).length();
if (i == end) if (i == end)
len -= len - end_col; len = end_col;
if (i == begin) if (i == begin)
len -= begin_col; len -= begin_col;
String new_line = text_editor->get_line(i).substr(i == begin ? begin_col : 0, len); String new_line = text_editor->get_line(i).substr(i == begin ? begin_col : 0, len);

View file

@ -4995,7 +4995,7 @@ void EditorNode::_feature_profile_changed() {
main_editor_buttons[EDITOR_3D]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D)); main_editor_buttons[EDITOR_3D]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D));
main_editor_buttons[EDITOR_SCRIPT]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT)); main_editor_buttons[EDITOR_SCRIPT]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT));
main_editor_buttons[EDITOR_ASSETLIB]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB)); main_editor_buttons[EDITOR_ASSETLIB]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB));
if (profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D) || profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB) || profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB)) { if (profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D) || profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT) || profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB)) {
_editor_select(EDITOR_2D); _editor_select(EDITOR_2D);
} }
} else { } else {

View file

@ -643,7 +643,7 @@ Ref<Texture> EditorAudioStreamPreviewPlugin::generate(const RES &p_from, const S
float max = -1000; float max = -1000;
float min = 1000; float min = 1000;
int from = uint64_t(i) * frame_length / w; int from = uint64_t(i) * frame_length / w;
int to = uint64_t(i + 1) * frame_length / w; int to = (uint64_t(i) + 1) * frame_length / w;
to = MIN(to, frame_length); to = MIN(to, frame_length);
from = MIN(from, frame_length - 1); from = MIN(from, frame_length - 1);
if (to == from) { if (to == from) {

View file

@ -394,15 +394,17 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
void SceneTreeEditor::_node_visibility_changed(Node *p_node) { void SceneTreeEditor::_node_visibility_changed(Node *p_node) {
if (p_node != get_scene_node() && !p_node->get_owner()) { if (!p_node || (p_node != get_scene_node() && !p_node->get_owner())) {
return; return;
} }
TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : NULL;
TreeItem *item = _find(tree->get_root(), p_node->get_path());
if (!item) { if (!item) {
return; return;
} }
int idx = item->get_button_by_id(0, BUTTON_VISIBILITY); int idx = item->get_button_by_id(0, BUTTON_VISIBILITY);
ERR_FAIL_COND(idx == -1); ERR_FAIL_COND(idx == -1);

View file

@ -1995,7 +1995,6 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to
} }
} }
ERR_FAIL_V(op);
} break; } break;
default: { default: {
return p_node; return p_node;

View file

@ -67,9 +67,7 @@ void NavigationMeshEditor::_bake_pressed() {
EditorNavigationMeshGenerator::get_singleton()->clear(node->get_navigation_mesh()); EditorNavigationMeshGenerator::get_singleton()->clear(node->get_navigation_mesh());
EditorNavigationMeshGenerator::get_singleton()->bake(node->get_navigation_mesh(), node); EditorNavigationMeshGenerator::get_singleton()->bake(node->get_navigation_mesh(), node);
if (node) { node->update_gizmo();
node->update_gizmo();
}
} }
void NavigationMeshEditor::_clear_pressed() { void NavigationMeshEditor::_clear_pressed() {

View file

@ -413,10 +413,11 @@ void VideoStreamPlaybackWebm::delete_pointers() {
if (audio_frame) if (audio_frame)
memdelete(audio_frame); memdelete(audio_frame);
for (int i = 0; i < video_frames_capacity; ++i) if (video_frames) {
memdelete(video_frames[i]); for (int i = 0; i < video_frames_capacity; ++i)
if (video_frames) memdelete(video_frames[i]);
memfree(video_frames); memfree(video_frames);
}
if (video) if (video)
memdelete(video); memdelete(video);

View file

@ -444,10 +444,10 @@ InputDefault::JoyAxis JoypadLinux::axis_correct(const input_absinfo *p_abs, int
jx.min = -1; jx.min = -1;
if (p_value < 0) { if (p_value < 0) {
jx.value = (float)-p_value / min; jx.value = (float)-p_value / min;
} else {
jx.value = (float)p_value / max;
} }
jx.value = (float)p_value / max; } else if (min == 0) {
}
if (min == 0) {
jx.min = 0; jx.min = 0;
jx.value = 0.0f + (float)p_value / max; jx.value = 0.0f + (float)p_value / max;
} }

View file

@ -44,15 +44,16 @@ void Camera2D::_update_scroll() {
return; return;
} }
if (!viewport)
return;
if (current) { if (current) {
ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id)); ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id));
Transform2D xform = get_camera_transform(); Transform2D xform = get_camera_transform();
if (viewport) { viewport->set_canvas_transform(xform);
viewport->set_canvas_transform(xform);
}
Size2 screen_size = viewport->get_visible_rect().size; Size2 screen_size = viewport->get_visible_rect().size;
Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5) : Point2()); Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5) : Point2());

View file

@ -1049,7 +1049,7 @@ AnimationNodeBlendTree::ConnectionError AnimationNodeBlendTree::can_connect_node
return CONNECTION_ERROR_NO_INPUT; return CONNECTION_ERROR_NO_INPUT;
} }
if (!nodes.has(p_input_node)) { if (p_input_node == p_output_node) {
return CONNECTION_ERROR_SAME_NODE; return CONNECTION_ERROR_SAME_NODE;
} }

View file

@ -318,7 +318,7 @@ void TreeItem::set_custom_draw(int p_column, Object *p_object, const StringName
void TreeItem::set_collapsed(bool p_collapsed) { void TreeItem::set_collapsed(bool p_collapsed) {
if (collapsed == p_collapsed) if (collapsed == p_collapsed || !tree)
return; return;
collapsed = p_collapsed; collapsed = p_collapsed;
TreeItem *ci = tree->selected_item; TreeItem *ci = tree->selected_item;
@ -344,8 +344,7 @@ void TreeItem::set_collapsed(bool p_collapsed) {
} }
_changed_notify(); _changed_notify();
if (tree) tree->emit_signal("item_collapsed", this);
tree->emit_signal("item_collapsed", this);
} }
bool TreeItem::is_collapsed() { bool TreeItem::is_collapsed() {