Skip to content

Commit

Permalink
Added/Fixed null pointer checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubonnek committed Aug 26, 2017
1 parent 53c0010 commit 7a07895
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 47 deletions.
5 changes: 1 addition & 4 deletions drivers/gles3/rasterizer_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion editor/animation_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions modules/visual_script/visual_script_func_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ class VisualScriptNodeInstanceFunctionCall : public VisualScriptNodeInstance {
}

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;
Expand Down Expand Up @@ -1596,7 +1596,7 @@ class VisualScriptNodeInstancePropertySet : public VisualScriptNodeInstance {
}

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;
Expand Down Expand Up @@ -2241,7 +2241,7 @@ class VisualScriptNodeInstancePropertyGet : public VisualScriptNodeInstance {
}

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;
Expand Down
2 changes: 1 addition & 1 deletion modules/visual_script/visual_script_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,7 @@ class VisualScriptNodeInstanceSceneNode : public VisualScriptNodeInstance {
}

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;
Expand Down
2 changes: 1 addition & 1 deletion modules/visual_script/visual_script_yield_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ class VisualScriptNodeInstanceYieldSignal : public VisualScriptNodeInstance {
}

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;
Expand Down
14 changes: 5 additions & 9 deletions platform/x11/os_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,33 +116,29 @@ 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) {
if (is_stdout_verbose()) {
WARN_PRINT("IME is disabled");
}
modifiers = XSetLocaleModifiers("@im=none");
}
if (modifiers == NULL) {
WARN_PRINT("Error setting locale modifiers");
}

Expand Down
13 changes: 7 additions & 6 deletions platform/x11/power_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2868,8 +2868,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) {

Expand Down
9 changes: 3 additions & 6 deletions servers/physics/broad_phase_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 8 additions & 6 deletions servers/visual/visual_server_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions servers/visual/visual_server_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7a07895

Please sign in to comment.