Merge pull request #10591 from Rubonnek/possible-null-ptr-dereference

Added/Fixed null pointer checks
This commit is contained in:
Rémi Verschelde 2017-08-27 02:10:56 +02:00 committed by GitHub
commit 612099e377
14 changed files with 39 additions and 47 deletions

View file

@ -247,11 +247,8 @@ void RasterizerGLES3::set_current_render_target(RID p_render_target) {
if (p_render_target.is_valid()) {
RasterizerStorageGLES3::RenderTarget *rt = storage->render_target_owner.getornull(p_render_target);
if (!rt) {
storage->frame.current_rt = NULL;
}
ERR_FAIL_COND(!rt);
storage->frame.current_rt = rt;
ERR_FAIL_COND(!rt);
storage->frame.clear_request = false;
glViewport(0, 0, rt->width, rt->height);

View file

@ -1646,7 +1646,7 @@ PropertyInfo AnimationKeyEditor::_find_hint_for_track(int p_idx, NodePath &r_bas
List<PropertyInfo> pinfo;
if (res.is_valid())
res->get_property_list(&pinfo);
else
else if (node)
node->get_property_list(&pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {

View file

@ -253,8 +253,8 @@ static void _create_script_templates(const String &p_path) {
dir->change_dir(p_path);
for (int i = 0; i < keys.size(); i++) {
if (!dir->file_exists(keys[i])) {
file->reopen(p_path.plus_file((String)keys[i]), FileAccess::WRITE);
ERR_FAIL_COND(!file);
Error err = file->reopen(p_path.plus_file((String)keys[i]), FileAccess::WRITE);
ERR_FAIL_COND(err != OK);
file->store_string(templates[keys[i]]);
file->close();
}

View file

@ -3766,7 +3766,7 @@ bool CanvasItemEditorViewport::_cyclical_dependency_exists(const String &p_targe
void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point) {
child->set_name(path.get_file().get_basename());
Ref<Texture> texture = Object::cast_to<Texture>(Ref<Texture>(ResourceCache::get(path)).ptr());
Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(ResourceCache::get(path)));
Size2 texture_size = texture->get_size();
editor_data->get_undo_redo().add_do_method(parent, "add_child", child);

View file

@ -822,7 +822,7 @@ public:
}
Node *another = node->get_node(node_path);
if (!node) {
if (!another) {
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
r_error_str = "Path does not lead Node!";
return 0;
@ -1596,7 +1596,7 @@ public:
}
Node *another = node->get_node(node_path);
if (!node) {
if (!another) {
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
r_error_str = "Path does not lead Node!";
return 0;
@ -2241,7 +2241,7 @@ public:
}
Node *another = node->get_node(node_path);
if (!node) {
if (!another) {
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
r_error_str = RTR("Path does not lead Node!");
return 0;

View file

@ -2087,7 +2087,7 @@ public:
}
Node *another = node->get_node(path);
if (!node) {
if (!another) {
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
r_error_str = "Path does not lead Node!";
return 0;

View file

@ -535,7 +535,7 @@ public:
}
Node *another = node->get_node(node_path);
if (!node) {
if (!another) {
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
r_error_str = "Path does not lead Node!";
return 0;

View file

@ -116,24 +116,22 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
/** XLIB INITIALIZATION **/
x11_display = XOpenDisplay(NULL);
char *modifiers = NULL;
Bool xkb_dar = False;
if (x11_display) {
XAutoRepeatOn(x11_display);
xkb_dar = XkbSetDetectableAutoRepeat(x11_display, True, NULL);
}
char *modifiers = NULL;
// Try to support IME if detectable auto-repeat is supported
if (xkb_dar == True) {
// Try to support IME if detectable auto-repeat is supported
if (xkb_dar == True) {
// Xutf8LookupString will be used later instead of XmbLookupString before
// the multibyte sequences can be converted to unicode string.
#ifdef X_HAVE_UTF8_STRING
modifiers = XSetLocaleModifiers("");
modifiers = XSetLocaleModifiers("");
#endif
}
}
if (modifiers == NULL) {
@ -141,8 +139,6 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
WARN_PRINT("IME is disabled");
}
modifiers = XSetLocaleModifiers("@im=none");
}
if (modifiers == NULL) {
WARN_PRINT("Error setting locale modifiers");
}

View file

@ -58,6 +58,7 @@ Adapted from corresponding SDL 2.0 code.
#include <stdio.h>
#include <unistd.h>
#include "core/error_macros.h"
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
@ -254,9 +255,9 @@ bool PowerX11::GetPowerInfo_Linux_proc_acpi() {
this->power_state = POWERSTATE_UNKNOWN;
dirp->change_dir(proc_acpi_battery_path);
dirp->list_dir_begin();
Error err = dirp->list_dir_begin();
if (dirp == NULL) {
if (err != OK) {
return false; /* can't use this interface. */
} else {
node = dirp->get_next();
@ -268,8 +269,8 @@ bool PowerX11::GetPowerInfo_Linux_proc_acpi() {
}
dirp->change_dir(proc_acpi_ac_adapter_path);
dirp->list_dir_begin();
if (dirp == NULL) {
err = dirp->list_dir_begin();
if (err != OK) {
return false; /* can't use this interface. */
} else {
node = dirp->get_next();
@ -438,9 +439,9 @@ bool PowerX11::GetPowerInfo_Linux_sys_class_power_supply(/*PowerState *state, in
DirAccess *dirp = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
dirp->change_dir(base);
dirp->list_dir_begin();
Error err = dirp->list_dir_begin();
if (!dirp) {
if (err != OK) {
return false;
}

View file

@ -215,8 +215,8 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
const Map<int, TextEdit::Text::ColorRegionInfo> &TextEdit::Text::get_color_region_info(int p_line) {
Map<int, ColorRegionInfo> *cri = NULL;
ERR_FAIL_INDEX_V(p_line, text.size(), *cri); //enjoy your crash
static Map<int, ColorRegionInfo> cri;
ERR_FAIL_INDEX_V(p_line, text.size(), cri);
if (text[p_line].width_cache == -1) {
_update_line_cache(p_line);

View file

@ -2870,8 +2870,8 @@ TreeItem *Tree::create_item(TreeItem *p_parent) {
TreeItem *ti = memnew(TreeItem(this));
ti->cells.resize(columns.size());
ERR_FAIL_COND_V(!ti, NULL);
ti->cells.resize(columns.size());
if (p_parent) {

View file

@ -30,17 +30,14 @@
#include "broad_phase_basic.h"
#include "list.h"
#include "print_string.h"
BroadPhaseSW::ID BroadPhaseBasic::create(CollisionObjectSW *p_object_, int p_subindex) {
BroadPhaseSW::ID BroadPhaseBasic::create(CollisionObjectSW *p_object, int p_subindex) {
if (p_object_ == NULL) {
ERR_FAIL_COND_V(p_object_ == NULL, 0);
}
ERR_FAIL_COND_V(p_object == NULL, NULL);
current++;
Element e;
e.owner = p_object_;
e.owner = p_object;
e._static = false;
e.subindex = p_subindex;

View file

@ -1099,13 +1099,15 @@ void VisualServerCanvas::canvas_light_occluder_set_polygon(RID p_occluder, RID p
if (occluder->polygon.is_valid()) {
LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_polygon);
if (!occluder_poly)
if (!occluder_poly) {
occluder->polygon = RID();
ERR_FAIL_COND(!occluder_poly);
occluder_poly->owners.insert(occluder);
occluder->polygon_buffer = occluder_poly->occluder;
occluder->aabb_cache = occluder_poly->aabb;
occluder->cull_cache = occluder_poly->cull_mode;
ERR_FAIL_COND(!occluder_poly);
} else {
occluder_poly->owners.insert(occluder);
occluder->polygon_buffer = occluder_poly->occluder;
occluder->aabb_cache = occluder_poly->aabb;
occluder->cull_cache = occluder_poly->cull_mode;
}
}
}
void VisualServerCanvas::canvas_light_occluder_set_transform(RID p_occluder, const Transform2D &p_xform) {

View file

@ -1482,11 +1482,10 @@ void VisualServerScene::_render_scene(const Transform p_cam_transform, const Cam
if (light && p_shadow_atlas.is_valid() && VSG::storage->light_has_shadow(E->get()->base)) {
lights_with_shadow[directional_shadow_count++] = E->get();
//add to list
directional_light_ptr[directional_light_count++] = light->instance;
}
//add to list
directional_light_ptr[directional_light_count++] = light->instance;
}
VSG::scene_render->set_directional_shadow_count(directional_shadow_count);