Fix crash on output extension fail
Steps to reproduce the crash:
- Open Inkscape
- Draw nothing
- Go to 'File -> Save As...' and select
GIMP XCF maintaining layers (*.xcf)as a file type - Click 'Save' (GIMP XCF dialog appears)
- Click 'OK' in the dialog
- A message window appears saying "This extension requires at least one non empty layer."
- Click 'OK' in the window
- (Crash)
Description
With new unnamed document, if 'Save As' extension fails, then this block is executed:
catch(...) {
if(check_overwrite && official) {
...
doc->changeFilenameAndHrefs(saved_filename);
}
...
Here saved_filename is nullptr, because earlier in the same function it is derived from current document filename:
gchar *saved_filename = g_strdup(doc->getDocumentFilename());
but new unnamed documents have no filename.
Then doc->changeFilenameAndHrefs(saved_filename) calls do_change_filename(filename, true); where the proposed MR applies. In the method, if filename argument is nullptr, then these three variables are set as follows:
new_document_name = g_strdup_printf(_("Unnamed document %d"), ++doc_count);
new_document_base = nullptr;
new_document_filename = nullptr;
Note the last one, new_document_filename = nullptr.
At the end of the method a signal is emitted to notify a filename change:
this->document_name = new_document_name;
this->document_base = new_document_base;
this->document_filename = new_document_filename;
this->filename_set_signal.emit(this->document_filename);
}
Here, in the emit() method this->document_filename is used, which was set to nullptr before. The signal is connected to SPDesktop::onDocumentFilenameSet (gchar const* filename), which only calls SPDesktopWidget::updateTitle(gchar const* uri) with filename as uri argument.
The crash occurs inside the updateTitle() method, on line 575:
std::string Name;
...
Name += uri;
As far as I can tell, Inkscape uses document_name and not full filename to show in the window title bar. So, the change this->document_filename to this->document_name seems reasonable.