TM: Don't allow passing NULL to tm_workspace API

This commit is contained in:
Colomban Wendling 2014-11-08 18:32:41 +01:00
parent 0ed236db30
commit 6a0673f4ae
3 changed files with 20 additions and 11 deletions

View File

@ -501,10 +501,13 @@ static gboolean handle_save_as(const gchar *utf8_filename, gboolean rename_file)
{
document_rename_file(doc, utf8_filename);
}
/* create a new tm_source_file object otherwise tagmanager won't work correctly */
tm_workspace_remove_source_file(doc->tm_file);
tm_source_file_free(doc->tm_file);
doc->tm_file = NULL;
if (doc->tm_file)
{
/* create a new tm_source_file object otherwise tagmanager won't work correctly */
tm_workspace_remove_source_file(doc->tm_file);
tm_source_file_free(doc->tm_file);
doc->tm_file = NULL;
}
}
success = document_save_file_as(doc, utf8_filename);

View File

@ -714,8 +714,11 @@ static gboolean remove_page(guint page_num)
g_free(doc->priv->saved_encoding.encoding);
g_free(doc->file_name);
g_free(doc->real_path);
tm_workspace_remove_source_file(doc->tm_file);
tm_source_file_free(doc->tm_file);
if (doc->tm_file)
{
tm_workspace_remove_source_file(doc->tm_file);
tm_source_file_free(doc->tm_file);
}
if (doc->priv->tag_tree)
gtk_widget_destroy(doc->priv->tag_tree);

View File

@ -202,9 +202,8 @@ void tm_workspace_update_source_file_buffer(TMSourceFile *source_file, guchar* t
void tm_workspace_remove_source_file(TMSourceFile *source_file)
{
guint i;
if (!source_file)
return;
g_return_if_fail(source_file != NULL);
for (i=0; i < theWorkspace->source_files->len; ++i)
{
@ -270,7 +269,9 @@ static void tm_workspace_update(void)
void tm_workspace_add_source_files(GPtrArray *source_files)
{
guint i;
g_return_if_fail(source_files != NULL);
for (i = 0; i < source_files->len; i++)
{
TMSourceFile *source_file = source_files->pdata[i];
@ -292,7 +293,9 @@ void tm_workspace_add_source_files(GPtrArray *source_files)
void tm_workspace_remove_source_files(GPtrArray *source_files)
{
guint i, j;
g_return_if_fail(source_files != NULL);
//TODO: sort both arrays by pointer value and remove in single pass
for (i = 0; i < source_files->len; i++)
{