Blame SOURCES/evince-3.28.2-covscan.patch

ba1789
--- evince-3.28.2/backend/comics/comics-document.c
ba1789
+++ evince-3.28.2/backend/comics/comics-document.c
ba1789
@@ -453,23 +453,27 @@ comics_document_render_pixbuf (EvDocumen
ba1789
 
ba1789
 		name = ev_archive_get_entry_pathname (comics_document->archive);
ba1789
 		if (g_strcmp0 (name, page_path) == 0) {
ba1789
-			size_t size = ev_archive_get_entry_size (comics_document->archive);
ba1789
+			gint64 size = ev_archive_get_entry_size (comics_document->archive);
ba1789
 			char *buf;
ba1789
 			ssize_t read;
ba1789
 
ba1789
-			buf = g_malloc (size);
ba1789
-			read = ev_archive_read_data (comics_document->archive, buf, size, &error);
ba1789
-			if (read <= 0) {
ba1789
-				if (read < 0) {
ba1789
-					g_warning ("Fatal error reading '%s' in archive: %s", name, error->message);
ba1789
-					g_error_free (error);
ba1789
+			if (size < 0) {
ba1789
+				g_warning ("Wrong size of entry '%s'.", name);
ba1789
+			} else {
ba1789
+				buf = g_malloc (size);
ba1789
+				read = ev_archive_read_data (comics_document->archive, buf, size, &error);
ba1789
+				if (read <= 0) {
ba1789
+					if (read < 0) {
ba1789
+						g_warning ("Fatal error reading '%s' in archive: %s", name, error->message);
ba1789
+						g_error_free (error);
ba1789
+					} else {
ba1789
+						g_warning ("Read an empty file from the archive");
ba1789
+					}
ba1789
 				} else {
ba1789
-					g_warning ("Read an empty file from the archive");
ba1789
+					gdk_pixbuf_loader_write (loader, (guchar *) buf, size, NULL);
ba1789
 				}
ba1789
-			} else {
ba1789
-				gdk_pixbuf_loader_write (loader, (guchar *) buf, size, NULL);
ba1789
+				g_free (buf);
ba1789
 			}
ba1789
-			g_free (buf);
ba1789
 			gdk_pixbuf_loader_close (loader, NULL);
ba1789
 			break;
ba1789
 		}
ba1789
--- evince-3.28.2/backend/pdf/ev-poppler.cc
ba1789
+++ evince-3.28.2/backend/pdf/ev-poppler.cc
ba1789
@@ -859,6 +859,7 @@ pdf_document_get_info (EvDocument *docum
ba1789
 			break;
ba1789
 		case POPPLER_PAGE_LAYOUT_TWO_COLUMN_RIGHT:
ba1789
 			info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_RIGHT;
ba1789
+			break;
ba1789
 		case POPPLER_PAGE_LAYOUT_TWO_PAGE_LEFT:
ba1789
 			info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_LEFT;
ba1789
 			break;
ba1789
--- evince-3.28.2/cut-n-paste/libgd/gd-two-lines-renderer.c
ba1789
+++ evince-3.28.2/cut-n-paste/libgd/gd-two-lines-renderer.c
ba1789
@@ -281,7 +281,7 @@ gd_two_lines_renderer_render (GtkCellRen
ba1789
   GtkStyleContext *context;
ba1789
   gint line_one_height;
ba1789
   GtkStateFlags state;
ba1789
-  GdkRectangle area, render_area = *cell_area;
ba1789
+  GdkRectangle area, render_area;
ba1789
   gint xpad, ypad, x_offset_1, x_offset_2, y_offset;
ba1789
   PangoLayout *layout_one, *layout_two;
ba1789
   PangoRectangle layout_rect;
ba1789
--- evince-3.28.2/cut-n-paste/synctex/synctex_parser.c
ba1789
+++ evince-3.28.2/cut-n-paste/synctex/synctex_parser.c
ba1789
@@ -2878,6 +2878,7 @@ int _synctex_open(const char * output, c
ba1789
 				build_output[0] = '\0';
ba1789
 			} else {
ba1789
 				if (build_output != strcpy(build_output,output)) {
ba1789
+					free(build_output);
ba1789
 					return -4;
ba1789
 				}
ba1789
 				build_output[lpc-output]='\0';
ba1789
@@ -2886,15 +2887,18 @@ int _synctex_open(const char * output, c
ba1789
 				/*	Append a path separator if necessary. */
ba1789
 				if (!SYNCTEX_IS_PATH_SEPARATOR(build_output[strlen(build_directory)-1])) {
ba1789
 					if (build_output != strcat(build_output,"/")) {
ba1789
+						free(build_output);
ba1789
 						return -2;
ba1789
 					}
ba1789
 				}
ba1789
 				/*	Append the last path component of the output. */
ba1789
 				if (build_output != strcat(build_output,lpc)) {
ba1789
+					free(build_output);
ba1789
 					return -3;
ba1789
 				}
ba1789
 				return __synctex_open(build_output,synctex_name_ref,file_ref,add_quotes,io_mode_ref);
ba1789
 			}
ba1789
+			free(build_output);
ba1789
 		}
ba1789
 		return -1;
ba1789
 	}
ba1789
--- evince-3.28.2/cut-n-paste/synctex/synctex_parser_utils.c
ba1789
+++ evince-3.28.2/cut-n-paste/synctex/synctex_parser_utils.c
ba1789
@@ -292,6 +292,7 @@ char * _synctex_merge_strings(const char
ba1789
 		size_t len = strlen(temp);
ba1789
 		if(UINT_MAX-len
ba1789
 			_synctex_error("!  _synctex_merge_strings: Capacity exceeded.");
ba1789
+			va_end(arg);
ba1789
 			return NULL;
ba1789
 		}
ba1789
 		size+=len;
ba1789
@@ -312,6 +313,7 @@ char * _synctex_merge_strings(const char
ba1789
 						_synctex_error("!  _synctex_merge_strings: Copy problem");
ba1789
 						free(result);
ba1789
 						result = NULL;
ba1789
+						va_end(arg);
ba1789
 						return NULL;
ba1789
 					}
ba1789
 					dest += size;
ba1789
@@ -393,7 +395,7 @@ int _synctex_get_name(const char * outpu
ba1789
 					free(dir_name);
ba1789
 					dir_name = NULL;
ba1789
 					free(core_name);
ba1789
-					dir_name = NULL;
ba1789
+					core_name = NULL;
ba1789
 					return -2;
ba1789
 				}
ba1789
 				dir_name[size] = '\0';
ba1789
@@ -487,6 +489,12 @@ int _synctex_get_name(const char * outpu
ba1789
             /* set up the returned values */
ba1789
             * synctex_name_ref = synctex_name;
ba1789
             * io_mode_ref = io_mode;
ba1789
+			free(dir_name);
ba1789
+			dir_name = NULL;
ba1789
+			free(core_name);
ba1789
+			core_name = NULL;
ba1789
+			free(quoted_core_name);
ba1789
+			quoted_core_name = NULL;
ba1789
 			return 0;
ba1789
 		}
ba1789
 		return -1;/*  bad argument */
ba1789
--- evince-3.28.2/cut-n-paste/unarr/rar/filter-rar.c
ba1789
+++ evince-3.28.2/cut-n-paste/unarr/rar/filter-rar.c
ba1789
@@ -273,8 +273,10 @@ static struct RARFilter *rar_create_filt
ba1789
     filter->prog = prog;
ba1789
     filter->globaldatalen = globaldatalen > RARProgramSystemGlobalSize ? globaldatalen : RARProgramSystemGlobalSize;
ba1789
     filter->globaldata = calloc(1, filter->globaldatalen);
ba1789
-    if (!filter->globaldata)
ba1789
+    if (!filter->globaldata) {
ba1789
+        free (filter);
ba1789
         return NULL;
ba1789
+    }
ba1789
     if (globaldata)
ba1789
         memcpy(filter->globaldata, globaldata, globaldatalen);
ba1789
     if (registers)
ba1789
--- evince-3.28.2/libdocument/ev-document.c
ba1789
+++ evince-3.28.2/libdocument/ev-document.c
ba1789
@@ -496,6 +496,9 @@ ev_document_load_stream (EvDocument
ba1789
         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
ba1789
 
ba1789
         klass = EV_DOCUMENT_GET_CLASS (document);
ba1789
+
ba1789
+        g_return_val_if_fail (klass != NULL, FALSE);
ba1789
+
ba1789
         if (!klass->load_stream) {
ba1789
                 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
ba1789
                                      "Backend does not support loading from stream");
ba1789
@@ -544,6 +547,9 @@ ev_document_load_gfile (EvDocument
ba1789
         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
ba1789
 
ba1789
         klass = EV_DOCUMENT_GET_CLASS (document);
ba1789
+
ba1789
+        g_return_val_if_fail (klass != NULL, FALSE);
ba1789
+
ba1789
         if (!klass->load_gfile) {
ba1789
                 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
ba1789
                                      "Backend does not support loading from GFile");
ba1789
@@ -867,6 +873,9 @@ ev_document_get_backend_info (EvDocument
ba1789
 	g_return_val_if_fail (EV_IS_DOCUMENT (document), FALSE);
ba1789
 
ba1789
 	klass = EV_DOCUMENT_GET_CLASS (document);
ba1789
+
ba1789
+        g_return_val_if_fail (klass != NULL, FALSE);
ba1789
+
ba1789
 	if (klass->get_backend_info == NULL)
ba1789
 		return FALSE;
ba1789
 
ba1789
--- evince-3.28.2/libview/ev-pixbuf-cache.c
ba1789
+++ evince-3.28.2/libview/ev-pixbuf-cache.c
ba1789
@@ -337,6 +337,11 @@ job_finished_cb (EvJob         *job,
ba1789
 
ba1789
 	job_info = find_job_cache (pixbuf_cache, job_render->page);
ba1789
 
ba1789
+	if (job_info == NULL) {
ba1789
+		g_warning ("Job info not found.");
ba1789
+		return;
ba1789
+	}
ba1789
+
ba1789
 	if (ev_job_is_failed (job)) {
ba1789
 		job_info->job = NULL;
ba1789
 		g_object_unref (job);
ba1789
@@ -721,6 +726,11 @@ add_job_if_needed (EvPixbufCache *pixbuf
ba1789
 	gint device_scale = get_device_scale (pixbuf_cache);
ba1789
 	gint width, height;
ba1789
 
ba1789
+	if (job_info == NULL) {
ba1789
+		g_warning ("Adding job with NULL info.");
ba1789
+		return;
ba1789
+	}
ba1789
+
ba1789
 	if (job_info->job)
ba1789
 		return;
ba1789
 
ba1789
--- evince-3.28.2/libview/ev-print-operation.c
ba1789
+++ evince-3.28.2/libview/ev-print-operation.c
ba1789
@@ -181,6 +181,7 @@ ev_print_operation_set_current_page (EvP
ba1789
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
ba1789
 
ba1789
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
ba1789
+	g_return_if_fail (class != NULL);
ba1789
 	g_return_if_fail (current_page >= 0);
ba1789
 
ba1789
 	class->set_current_page (op, current_page);
ba1789
@@ -193,6 +194,7 @@ ev_print_operation_set_print_settings (E
ba1789
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
ba1789
 
ba1789
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
ba1789
+	g_return_if_fail (class != NULL);
ba1789
 	g_return_if_fail (GTK_IS_PRINT_SETTINGS (print_settings));
ba1789
 
ba1789
 	class->set_print_settings (op, print_settings);
ba1789
@@ -210,6 +212,7 @@ ev_print_operation_get_print_settings (E
ba1789
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
ba1789
 
ba1789
 	g_return_val_if_fail (EV_IS_PRINT_OPERATION (op), NULL);
ba1789
+	g_return_val_if_fail (class != NULL, NULL);
ba1789
 
ba1789
 	return class->get_print_settings (op);
ba1789
 }
ba1789
@@ -221,6 +224,7 @@ ev_print_operation_set_default_page_setu
ba1789
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
ba1789
 
ba1789
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
ba1789
+	g_return_if_fail (class != NULL);
ba1789
 	g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
ba1789
 
ba1789
 	class->set_default_page_setup (op, page_setup);
ba1789
@@ -238,6 +242,7 @@ ev_print_operation_get_default_page_setu
ba1789
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
ba1789
 
ba1789
 	g_return_val_if_fail (EV_IS_PRINT_OPERATION (op), NULL);
ba1789
+	g_return_val_if_fail (class != NULL, NULL);
ba1789
 
ba1789
 	return class->get_default_page_setup (op);
ba1789
 }
ba1789
@@ -249,6 +254,7 @@ ev_print_operation_set_job_name (EvPrint
ba1789
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
ba1789
 
ba1789
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
ba1789
+	g_return_if_fail (class != NULL);
ba1789
 	g_return_if_fail (job_name != NULL);
ba1789
 
ba1789
 	class->set_job_name (op, job_name);
ba1789
@@ -260,6 +266,7 @@ ev_print_operation_get_job_name (EvPrint
ba1789
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
ba1789
 
ba1789
 	g_return_val_if_fail (EV_IS_PRINT_OPERATION (op), NULL);
ba1789
+	g_return_val_if_fail (class != NULL, NULL);
ba1789
 
ba1789
 	return class->get_job_name (op);
ba1789
 }
ba1789
@@ -271,6 +278,7 @@ ev_print_operation_run (EvPrintOperation
ba1789
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
ba1789
 
ba1789
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
ba1789
+	g_return_if_fail (class != NULL);
ba1789
 
ba1789
 	class->run (op, parent);
ba1789
 }
ba1789
@@ -281,6 +289,7 @@ ev_print_operation_cancel (EvPrintOperat
ba1789
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
ba1789
 
ba1789
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
ba1789
+	g_return_if_fail (class != NULL);
ba1789
 
ba1789
 	class->cancel (op);
ba1789
 }
ba1789
@@ -292,6 +301,7 @@ ev_print_operation_get_error (EvPrintOpe
ba1789
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
ba1789
 
ba1789
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
ba1789
+	g_return_if_fail (class != NULL);
ba1789
 
ba1789
 	class->get_error (op, error);
ba1789
 }
ba1789
@@ -303,6 +313,7 @@ ev_print_operation_set_embed_page_setup
ba1789
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
ba1789
 
ba1789
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
ba1789
+	g_return_if_fail (class != NULL);
ba1789
 
ba1789
 	class->set_embed_page_setup (op, embed);
ba1789
 }
ba1789
@@ -313,6 +324,7 @@ ev_print_operation_get_embed_page_setup
ba1789
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
ba1789
 
ba1789
 	g_return_val_if_fail (EV_IS_PRINT_OPERATION (op), FALSE);
ba1789
+	g_return_val_if_fail (class != NULL, FALSE);
ba1789
 
ba1789
 	return class->get_embed_page_setup (op);
ba1789
 }
ba1789
--- evince-3.28.2/libview/ev-timeline.c
ba1789
+++ evince-3.28.2/libview/ev-timeline.c
ba1789
@@ -289,9 +289,15 @@ ev_timeline_new (guint duration)
ba1789
 void
ba1789
 ev_timeline_start (EvTimeline *timeline)
ba1789
 {
ba1789
+	EvTimelineClass *klass;
ba1789
+
ba1789
 	g_return_if_fail (EV_IS_TIMELINE (timeline));
ba1789
 
ba1789
-	EV_TIMELINE_GET_CLASS (timeline)->start (timeline);
ba1789
+	klass = EV_TIMELINE_GET_CLASS (timeline);
ba1789
+
ba1789
+	g_return_if_fail (klass != NULL);
ba1789
+
ba1789
+	klass->start (timeline);
ba1789
 }
ba1789
 
ba1789
 void
ba1789
--- evince-3.28.2/libview/ev-view.c
ba1789
+++ evince-3.28.2/libview/ev-view.c
ba1789
@@ -1147,7 +1147,7 @@ ensure_rectangle_is_visible (EvView *vie
ba1789
 	if (rect->x < adj_value) {
ba1789
 		value = MAX (gtk_adjustment_get_lower (adjustment), rect->x - MARGIN);
ba1789
 		gtk_adjustment_set_value (view->hadjustment, value);
ba1789
-	} else if (rect->x + rect->height > adj_value + allocation.width) {
ba1789
+	} else if (rect->x + rect->width > adj_value + allocation.width) {
ba1789
 		value = MIN (gtk_adjustment_get_upper (adjustment), rect->x + rect->width -
ba1789
 			     allocation.width + MARGIN);
ba1789
 		gtk_adjustment_set_value (view->hadjustment, value);
ba1789
@@ -1777,6 +1777,11 @@ goto_fitv_dest (EvView *view, EvLinkDest
ba1789
 
ba1789
 	page = ev_link_dest_get_page (dest);
ba1789
 
ba1789
+	if (page < 0) {
ba1789
+		g_warning ("Link does not contain a page.");
ba1789
+		return;
ba1789
+	}
ba1789
+
ba1789
 	left = ev_link_dest_get_left (dest, &change_left);
ba1789
 	doc_point.x = change_left ? left : 0;
ba1789
 	doc_point.y = 0;
ba1789
@@ -1813,6 +1818,11 @@ goto_fith_dest (EvView *view, EvLinkDest
ba1789
 
ba1789
 	page = ev_link_dest_get_page (dest);
ba1789
 
ba1789
+	if (page < 0) {
ba1789
+		g_warning ("Link does not contain a page.");
ba1789
+		return;
ba1789
+	}
ba1789
+
ba1789
 	top = ev_link_dest_get_top (dest, &change_top);
ba1789
 	doc_point.x = 0;
ba1789
 	doc_point.y = change_top ? top : 0;
ba1789
@@ -1846,6 +1856,11 @@ goto_fit_dest (EvView *view, EvLinkDest
ba1789
 
ba1789
 	page = ev_link_dest_get_page (dest);
ba1789
 
ba1789
+	if (page < 0) {
ba1789
+		g_warning ("Link does not contain a page.");
ba1789
+		return;
ba1789
+	}
ba1789
+
ba1789
 	if (view->allow_links_change_zoom) {
ba1789
 		double zoom;
ba1789
 		gdouble doc_width, doc_height;
ba1789
--- evince-3.28.2/libview/ev-view-presentation.c
ba1789
+++ evince-3.28.2/libview/ev-view-presentation.c
ba1789
@@ -448,7 +448,7 @@ ev_view_presentation_update_current_page
ba1789
 {
ba1789
 	gint jump;
ba1789
 
ba1789
-	if (page < 0 || page >= ev_document_get_n_pages (pview->document))
ba1789
+	if (page >= ev_document_get_n_pages (pview->document))
ba1789
 		return;
ba1789
 
ba1789
 	ev_view_presentation_animation_cancel (pview);
ba1789
--- evince-3.28.2/shell/ev-sidebar.c
ba1789
+++ evince-3.28.2/shell/ev-sidebar.c
ba1789
@@ -471,18 +471,19 @@ ev_sidebar_add_page (EvSidebar   *ev_sid
ba1789
 
ba1789
 
ba1789
 	/* Set the first item added as active */
ba1789
-	gtk_tree_model_get_iter_first (ev_sidebar->priv->page_model, &iter);
ba1789
-	gtk_tree_model_get (ev_sidebar->priv->page_model,
ba1789
-			    &iter,
ba1789
-			    PAGE_COLUMN_TITLE, &label_title,
ba1789
-			    PAGE_COLUMN_NOTEBOOK_INDEX, &index,
ba1789
-			    -1);
ba1789
+	if (gtk_tree_model_get_iter_first (ev_sidebar->priv->page_model, &iter)) {
ba1789
+		gtk_tree_model_get (ev_sidebar->priv->page_model,
ba1789
+				    &iter,
ba1789
+				    PAGE_COLUMN_TITLE, &label_title,
ba1789
+				    PAGE_COLUMN_NOTEBOOK_INDEX, &index,
ba1789
+				    -1);
ba1789
 
ba1789
-	gtk_menu_set_active (GTK_MENU (ev_sidebar->priv->menu), index);
ba1789
-	gtk_label_set_text (GTK_LABEL (ev_sidebar->priv->label), label_title);
ba1789
-	gtk_notebook_set_current_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
ba1789
-				       index);
ba1789
-	g_free (label_title);
ba1789
+		gtk_menu_set_active (GTK_MENU (ev_sidebar->priv->menu), index);
ba1789
+		gtk_label_set_text (GTK_LABEL (ev_sidebar->priv->label), label_title);
ba1789
+		gtk_notebook_set_current_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
ba1789
+					       index);
ba1789
+		g_free (label_title);
ba1789
+	}
ba1789
 }
ba1789
 
ba1789
 static gboolean
ba1789
--- evince-3.28.2/shell/ev-sidebar-thumbnails.c
ba1789
+++ evince-3.28.2/shell/ev-sidebar-thumbnails.c
ba1789
@@ -658,11 +658,11 @@ ev_sidebar_thumbnails_fill_model (EvSide
ba1789
 	int i;
ba1789
 	gint prev_width = -1;
ba1789
 	gint prev_height = -1;
ba1789
+	cairo_surface_t *loading_icon = NULL;
ba1789
 
ba1789
 	for (i = 0; i < sidebar_thumbnails->priv->n_pages; i++) {
ba1789
 		gchar     *page_label;
ba1789
 		gchar     *page_string;
ba1789
-		cairo_surface_t *loading_icon = NULL;
ba1789
 		gint       width, height;
ba1789
 
ba1789
 		page_label = ev_document_get_page_label (priv->document, i);
ba1789
--- evince-3.28.2/shell/ev-window.c
ba1789
+++ evince-3.28.2/shell/ev-window.c
ba1789
@@ -3121,10 +3121,10 @@ ev_window_load_print_settings_from_metad
ba1789
 	for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
ba1789
 		gchar *value = NULL;
ba1789
 
ba1789
-		ev_metadata_get_string (window->priv->metadata,
ba1789
-					document_print_settings[i], &value);
ba1789
-		gtk_print_settings_set (print_settings,
ba1789
-					document_print_settings[i], value);
ba1789
+		if (ev_metadata_get_string (window->priv->metadata,
ba1789
+					    document_print_settings[i], &value))
ba1789
+			gtk_print_settings_set (print_settings,
ba1789
+						document_print_settings[i], value);
ba1789
 	}
ba1789
 }
ba1789
 
ba1789
@@ -4705,12 +4705,16 @@ ev_window_cmd_bookmarks_add (GSimpleActi
ba1789
 	gchar     *page_label;
ba1789
 
ba1789
 	bm.page = ev_document_model_get_page (window->priv->model);
ba1789
-	page_label = ev_document_get_page_label (window->priv->document, bm.page);
ba1789
-	bm.title = g_strdup_printf (_("Page %s"), page_label);
ba1789
-	g_free (page_label);
ba1789
+	if (bm.page >= 0) {
ba1789
+		page_label = ev_document_get_page_label (window->priv->document, bm.page);
ba1789
+		bm.title = g_strdup_printf (_("Page %s"), page_label);
ba1789
+		g_free (page_label);
ba1789
 
ba1789
-	/* EvBookmarks takes ownership of bookmark */
ba1789
-	ev_bookmarks_add (window->priv->bookmarks, &bm;;
ba1789
+		/* EvBookmarks takes ownership of bookmark */
ba1789
+		ev_bookmarks_add (window->priv->bookmarks, &bm;;
ba1789
+	} else {
ba1789
+		g_warning ("Bookmarking of a page failed.");
ba1789
+	}
ba1789
 }
ba1789
 
ba1789
 static void