diff options
| author | Kris De Gussem <kris.degussem@gmail.com> | 2013-04-08 06:10:27 +0000 |
|---|---|---|
| committer | Kris <Kris.De.Gussem@hotmail.com> | 2013-04-08 06:10:27 +0000 |
| commit | fa74436561b0b28b9fa967101d44b4e7d6530871 (patch) | |
| tree | 968e14c0ac64e8d8c5aaaad804b100bb7a4e0fa9 /src/extension/implementation | |
| parent | Added simple control to font dialog to address text on path's startOffset. Bu... (diff) | |
| download | inkscape-fa74436561b0b28b9fa967101d44b4e7d6530871.tar.gz inkscape-fa74436561b0b28b9fa967101d44b4e7d6530871.zip | |
NULL pointer checks
(bzr r12271)
Diffstat (limited to 'src/extension/implementation')
| -rw-r--r-- | src/extension/implementation/script.cpp | 81 |
1 files changed, 48 insertions, 33 deletions
diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index 3ac1e06ab..69ce982d0 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -669,8 +669,13 @@ void Script::effect(Inkscape::Extension::Effect *module, printf("TOO BAD TO LIVE!!!"); exit(1); } + if (doc == NULL) + { + g_warning("Script::effect: View not defined"); + return; + } - SPDesktop *desktop = (SPDesktop *)doc; + SPDesktop *desktop = reinterpret_cast<SPDesktop *>(doc); sp_namedview_document_from_window(desktop); std::list<std::string> params; @@ -696,16 +701,14 @@ void Script::effect(Inkscape::Extension::Effect *module, return; } - if (desktop != NULL) { - Inkscape::Util::GSListConstIterator<SPItem *> selected = - sp_desktop_selection(desktop)->itemList(); - while ( selected != NULL ) { - Glib::ustring selected_id; - selected_id += "--id="; - selected_id += (*selected)->getId(); - params.insert(params.begin(), selected_id); - ++selected; - } + Inkscape::Util::GSListConstIterator<SPItem *> selected = + sp_desktop_selection(desktop)->itemList(); //desktop should not be NULL since doc was checked and desktop is a casted pointer + while ( selected != NULL ) { + Glib::ustring selected_id; + selected_id += "--id="; + selected_id += (*selected)->getId(); + params.insert(params.begin(), selected_id); + ++selected; } file_listener fileout; @@ -728,30 +731,37 @@ void Script::effect(Inkscape::Extension::Effect *module, g_unlink(tempfilename_out.c_str()); - /* Do something with mydoc.... */ if (mydoc) { - doc->doc()->emitReconstructionStart(); - copy_doc(doc->doc()->rroot, mydoc->rroot); - doc->doc()->emitReconstructionFinish(); - SPObject *layer = NULL; - - // Getting the named view from the document generated by the extension - SPNamedView *nv = sp_document_namedview(mydoc, NULL); - - //Check if it has a default layer set up - if ( nv != NULL){ - if( nv->default_layer_id != 0 ) { - SPDocument *document = desktop->doc(); - //If so, get that layer - layer = document->getObjectById(g_quark_to_string(nv->default_layer_id)); + SPDocument* vd=doc->doc(); + if (vd != NULL) + { + vd->emitReconstructionStart(); + copy_doc(vd->rroot, mydoc->rroot); + vd->emitReconstructionFinish(); + SPObject *layer = NULL; + + // Getting the named view from the document generated by the extension + SPNamedView *nv = sp_document_namedview(mydoc, NULL); + + //Check if it has a default layer set up + if ( nv != NULL) + { + if( nv->default_layer_id != 0 ) { + SPDocument *document = desktop->doc(); + //If so, get that layer + if (document != NULL) + { + layer = document->getObjectById(g_quark_to_string(nv->default_layer_id)); + } + } + } + + sp_namedview_update_layers_from_document(desktop); + //If that layer exists, + if (layer) { + //set the current layer + desktop->setCurrentLayer(layer); } - } - - sp_namedview_update_layers_from_document(desktop); - //If that layer exists, - if (layer) { - //set the current layer - desktop->setCurrentLayer(layer); } mydoc->release(); } @@ -778,6 +788,11 @@ void Script::effect(Inkscape::Extension::Effect *module, */ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newroot) { + if ((oldroot == NULL) ||(newroot == NULL)) + { + g_warning("Error on copy_doc: NULL pointer input."); + return; + } std::vector<Inkscape::XML::Node *> delete_list; Inkscape::XML::Node * oldroot_namedview = NULL; |
