Blame SOURCES/evince-40.1-covscan.patch

96292f
--- evince-40.1/backend/dvi/mdvi-lib/pagesel.c
96292f
+++ evince-40.1/backend/dvi/mdvi-lib/pagesel.c
96292f
@@ -209,6 +209,7 @@ DviPageSpec *mdvi_parse_page_spec(const
96292f
 		range = mdvi_parse_range(format, NULL, &count, &ptr);
96292f
 		if(ptr == format) {
96292f
 			if(range) mdvi_free(range);
96292f
+			mdvi_free(spec);
96292f
 			mdvi_error(_("invalid page specification `%s'\n"), format);
96292f
 			return NULL;
96292f
 		}
96292f
--- evince-40.1/backend/dvi/mdvi-lib/tfmfile.c
96292f
+++ evince-40.1/backend/dvi/mdvi-lib/tfmfile.c
96292f
@@ -393,6 +393,7 @@ static int ofm1_load_file(FILE *in, TFMI
96292f
 	/* read them in one sweep */
96292f
 	if(fread(tfm, 4, size, in) != size) {
96292f
 		mdvi_free(tfm);
96292f
+		tfm = NULL;
96292f
 		goto bad_tfm;
96292f
 	}
96292f
 
96292f
--- evince-40.1/backend/dvi/mdvi-lib/vf.c
96292f
+++ evince-40.1/backend/dvi/mdvi-lib/vf.c
96292f
@@ -129,6 +129,7 @@ static int vf_load_font(DviParams *param
96292f
 		if(ref == NULL) {
96292f
 			mdvi_error(_("(vf) %s: could not load font `%s'\n"), 
96292f
 				   font->fontname, name);
96292f
+			mdvi_free(name);
96292f
 			goto error;
96292f
 		}
96292f
 		mdvi_free(name);
96292f
--- evince-40.1/backend/comics/comics-document.c
96292f
+++ evince-40.1/backend/comics/comics-document.c
96292f
@@ -453,23 +453,27 @@ comics_document_render_pixbuf (EvDocumen
96292f
 
96292f
 		name = ev_archive_get_entry_pathname (comics_document->archive);
96292f
 		if (g_strcmp0 (name, page_path) == 0) {
96292f
-			size_t size = ev_archive_get_entry_size (comics_document->archive);
96292f
+			gint64 size = ev_archive_get_entry_size (comics_document->archive);
96292f
 			char *buf;
96292f
 			ssize_t read;
96292f
 
96292f
-			buf = g_malloc (size);
96292f
-			read = ev_archive_read_data (comics_document->archive, buf, size, &error);
96292f
-			if (read <= 0) {
96292f
-				if (read < 0) {
96292f
-					g_warning ("Fatal error reading '%s' in archive: %s", name, error->message);
96292f
-					g_error_free (error);
96292f
+			if (size < 0) {
96292f
+				g_warning ("Wrong size of entry '%s'.", name);
96292f
+			} else {
96292f
+				buf = g_malloc (size);
96292f
+				read = ev_archive_read_data (comics_document->archive, buf, size, &error);
96292f
+				if (read <= 0) {
96292f
+					if (read < 0) {
96292f
+						g_warning ("Fatal error reading '%s' in archive: %s", name, error->message);
96292f
+						g_error_free (error);
96292f
+					} else {
96292f
+						g_warning ("Read an empty file from the archive");
96292f
+					}
96292f
 				} else {
96292f
-					g_warning ("Read an empty file from the archive");
96292f
+					gdk_pixbuf_loader_write (loader, (guchar *) buf, size, NULL);
96292f
 				}
96292f
-			} else {
96292f
-				gdk_pixbuf_loader_write (loader, (guchar *) buf, size, NULL);
96292f
+				g_free (buf);
96292f
 			}
96292f
-			g_free (buf);
96292f
 			gdk_pixbuf_loader_close (loader, NULL);
96292f
 			break;
96292f
 		}
96292f
--- evince-40.1/backend/pdf/ev-poppler.cc
96292f
+++ evince-40.1/backend/pdf/ev-poppler.cc
96292f
@@ -591,7 +591,7 @@ pdf_document_get_xmptag_from_path (xmlXP
96292f
                                    const char* xpath)
96292f
 {
96292f
 	xmlXPathObjectPtr xpathObj;
96292f
-	char *xmpmetapath = g_strdup_printf ("%s%s", "/x:xmpmeta", xpath);
96292f
+	char *xmpmetapath;
96292f
 	xmlChar *result = NULL;
96292f
 
96292f
 	/* add pdf/a and pdf/x namespaces */
96292f
@@ -620,13 +620,17 @@ pdf_document_get_xmptag_from_path (xmlXP
96292f
 	if (result != NULL)
96292f
 		return result;
96292f
 
96292f
+	xmpmetapath = g_strdup_printf ("%s%s", "/x:xmpmeta", xpath);
96292f
+
96292f
 	/*
96292f
 	Try in /x:xmpmeta/ (xmpmeta is optional)
96292f
 	https://wwwimages2.adobe.com/content/dam/acom/en/devnet/xmp/pdfs/XMP SDK Release cc-2016-08/XMPSpecificationPart1.pdf (Section 7.3.3)
96292f
 	*/
96292f
 	xpathObj = xmlXPathEvalExpression (BAD_CAST xmpmetapath, xpathCtx);
96292f
-	if (xpathObj == NULL)
96292f
+	if (xpathObj == NULL) {
96292f
+			g_free (xmpmetapath);
96292f
 			return NULL;
96292f
+	}
96292f
 
96292f
 	if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr != 0)
96292f
 			result = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
96292f
@@ -743,12 +747,14 @@ static char *
96292f
 pdf_document_get_author_from_metadata (xmlXPathContextPtr xpathCtx)
96292f
 {
96292f
 	char* result = NULL;
96292f
-	char* xmpmetapath = g_strdup_printf ("%s%s", "/x:xmpmeta", AUTHORS);
96292f
+	char* xmpmetapath;
96292f
 	/* Try in /rdf:RDF/ */
96292f
 	result = pdf_document_get_lists_from_dc_tags (xpathCtx, AUTHORS);
96292f
 	if (result != NULL)
96292f
 		return result;
96292f
 
96292f
+	xmpmetapath = g_strdup_printf ("%s%s", "/x:xmpmeta", AUTHORS);
96292f
+
96292f
 	/* Try in /x:xmpmeta/ */
96292f
 	result = pdf_document_get_lists_from_dc_tags (xpathCtx, xmpmetapath);
96292f
 	g_free (xmpmetapath);
96292f
@@ -760,12 +766,14 @@ static char *
96292f
 pdf_document_get_keywords_from_metadata (xmlXPathContextPtr xpathCtx)
96292f
 {
96292f
 	char* result = NULL;
96292f
-	char* xmpmetapath = g_strdup_printf ("%s%s", "/x:xmpmeta", KEYWORDS);
96292f
+	char* xmpmetapath;
96292f
 	/* Try in /rdf:RDF/ */
96292f
 	result = pdf_document_get_lists_from_dc_tags (xpathCtx, KEYWORDS);
96292f
 	if (result != NULL)
96292f
 		return result;
96292f
 
96292f
+	xmpmetapath = g_strdup_printf ("%s%s", "/x:xmpmeta", KEYWORDS);
96292f
+
96292f
 	/* Try in /x:xmpmeta/ */
96292f
 	result = pdf_document_get_lists_from_dc_tags (xpathCtx, xmpmetapath);
96292f
 	g_free (xmpmetapath);
96292f
@@ -859,6 +859,7 @@ pdf_document_get_info (EvDocument *docum
96292f
 			break;
96292f
 		case POPPLER_PAGE_LAYOUT_TWO_COLUMN_RIGHT:
96292f
 			info->layout = EV_DOCUMENT_LAYOUT_TWO_COLUMN_RIGHT;
96292f
+			break;
96292f
 		case POPPLER_PAGE_LAYOUT_TWO_PAGE_LEFT:
96292f
 			info->layout = EV_DOCUMENT_LAYOUT_TWO_PAGE_LEFT;
96292f
 			break;
96292f
--- evince-40.1/properties/ev-properties-view.c
96292f
+++ evince-40.1/properties/ev-properties-view.c
96292f
@@ -339,6 +339,7 @@ ev_regular_paper_size (const EvDocumentI
96292f
 		    ABS (info->paper_width  - paper_width) <= width_tolerance) {
96292f
 			/* Note to translators: first placeholder is the paper name (eg.
96292f
 			 * A4), second placeholder is the paper size (eg. 297x210 mm) */
96292f
+			g_free (str);
96292f
 			str = g_strdup_printf (_("%s, Portrait (%s)"),
96292f
 					       gtk_paper_size_get_display_name (size),
96292f
 					       exact_size);
96292f
@@ -346,6 +347,7 @@ ev_regular_paper_size (const EvDocumentI
96292f
 			   ABS (info->paper_height - paper_width) <= width_tolerance) {
96292f
 			/* Note to translators: first placeholder is the paper name (eg.
96292f
 			 * A4), second placeholder is the paper size (eg. 297x210 mm) */
96292f
+			g_free (str);
96292f
 			str = g_strdup_printf ( _("%s, Landscape (%s)"),
96292f
 						gtk_paper_size_get_display_name (size),
96292f
 						exact_size);
96292f
--- evince-40.1/cut-n-paste/libgd/gd-two-lines-renderer.c
96292f
+++ evince-40.1/cut-n-paste/libgd/gd-two-lines-renderer.c
96292f
@@ -281,7 +281,7 @@ gd_two_lines_renderer_render (GtkCellRen
96292f
   GtkStyleContext *context;
96292f
   gint line_one_height;
96292f
   GtkStateFlags state;
96292f
-  GdkRectangle area, render_area = *cell_area;
96292f
+  GdkRectangle area, render_area;
96292f
   gint xpad, ypad, x_offset_1, x_offset_2, y_offset;
96292f
   PangoLayout *layout_one, *layout_two;
96292f
   PangoRectangle layout_rect;
96292f
--- evince-40.1/cut-n-paste/unarr/rar/filter-rar.c
96292f
+++ evince-40.1/cut-n-paste/unarr/rar/filter-rar.c
96292f
@@ -273,8 +273,10 @@ static struct RARFilter *rar_create_filt
96292f
     filter->prog = prog;
96292f
     filter->globaldatalen = globaldatalen > RARProgramSystemGlobalSize ? globaldatalen : RARProgramSystemGlobalSize;
96292f
     filter->globaldata = calloc(1, filter->globaldatalen);
96292f
-    if (!filter->globaldata)
96292f
+    if (!filter->globaldata) {
96292f
+        free (filter);
96292f
         return NULL;
96292f
+    }
96292f
     if (globaldata)
96292f
         memcpy(filter->globaldata, globaldata, globaldatalen);
96292f
     if (registers)
96292f
--- evince-40.1/libdocument/ev-document.c
96292f
+++ evince-40.1/libdocument/ev-document.c
96292f
@@ -496,6 +496,9 @@ ev_document_load_stream (EvDocument
96292f
         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
96292f
 
96292f
         klass = EV_DOCUMENT_GET_CLASS (document);
96292f
+
96292f
+        g_return_val_if_fail (klass != NULL, FALSE);
96292f
+
96292f
         if (!klass->load_stream) {
96292f
                 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
96292f
                                      "Backend does not support loading from stream");
96292f
@@ -544,6 +547,9 @@ ev_document_load_gfile (EvDocument
96292f
         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
96292f
 
96292f
         klass = EV_DOCUMENT_GET_CLASS (document);
96292f
+
96292f
+        g_return_val_if_fail (klass != NULL, FALSE);
96292f
+
96292f
         if (!klass->load_gfile) {
96292f
                 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
96292f
                                      "Backend does not support loading from GFile");
96292f
@@ -867,6 +873,9 @@ ev_document_get_backend_info (EvDocument
96292f
 	g_return_val_if_fail (EV_IS_DOCUMENT (document), FALSE);
96292f
 
96292f
 	klass = EV_DOCUMENT_GET_CLASS (document);
96292f
+
96292f
+        g_return_val_if_fail (klass != NULL, FALSE);
96292f
+
96292f
 	if (klass->get_backend_info == NULL)
96292f
 		return FALSE;
96292f
 
96292f
--- evince-40.1/libview/ev-pixbuf-cache.c
96292f
+++ evince-40.1/libview/ev-pixbuf-cache.c
96292f
@@ -337,6 +337,11 @@ job_finished_cb (EvJob         *job,
96292f
 
96292f
 	job_info = find_job_cache (pixbuf_cache, job_render->page);
96292f
 
96292f
+	if (job_info == NULL) {
96292f
+		g_warning ("Job info not found.");
96292f
+		return;
96292f
+	}
96292f
+
96292f
 	if (ev_job_is_failed (job)) {
96292f
 		job_info->job = NULL;
96292f
 		g_object_unref (job);
96292f
@@ -721,6 +726,11 @@ add_job_if_needed (EvPixbufCache *pixbuf
96292f
 	gint device_scale = get_device_scale (pixbuf_cache);
96292f
 	gint width, height;
96292f
 
96292f
+	if (job_info == NULL) {
96292f
+		g_warning ("Adding job with NULL info.");
96292f
+		return;
96292f
+	}
96292f
+
96292f
 	if (job_info->job)
96292f
 		return;
96292f
 
96292f
--- evince-40.1/libview/ev-print-operation.c
96292f
+++ evince-40.1/libview/ev-print-operation.c
96292f
@@ -181,6 +181,7 @@ ev_print_operation_set_current_page (EvP
96292f
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
96292f
 
96292f
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
96292f
+	g_return_if_fail (class != NULL);
96292f
 	g_return_if_fail (current_page >= 0);
96292f
 
96292f
 	class->set_current_page (op, current_page);
96292f
@@ -193,6 +194,7 @@ ev_print_operation_set_print_settings (E
96292f
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
96292f
 
96292f
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
96292f
+	g_return_if_fail (class != NULL);
96292f
 	g_return_if_fail (GTK_IS_PRINT_SETTINGS (print_settings));
96292f
 
96292f
 	class->set_print_settings (op, print_settings);
96292f
@@ -210,6 +212,7 @@ ev_print_operation_get_print_settings (E
96292f
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
96292f
 
96292f
 	g_return_val_if_fail (EV_IS_PRINT_OPERATION (op), NULL);
96292f
+	g_return_val_if_fail (class != NULL, NULL);
96292f
 
96292f
 	return class->get_print_settings (op);
96292f
 }
96292f
@@ -221,6 +224,7 @@ ev_print_operation_set_default_page_setu
96292f
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
96292f
 
96292f
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
96292f
+	g_return_if_fail (class != NULL);
96292f
 	g_return_if_fail (GTK_IS_PAGE_SETUP (page_setup));
96292f
 
96292f
 	class->set_default_page_setup (op, page_setup);
96292f
@@ -238,6 +242,7 @@ ev_print_operation_get_default_page_setu
96292f
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
96292f
 
96292f
 	g_return_val_if_fail (EV_IS_PRINT_OPERATION (op), NULL);
96292f
+	g_return_val_if_fail (class != NULL, NULL);
96292f
 
96292f
 	return class->get_default_page_setup (op);
96292f
 }
96292f
@@ -249,6 +254,7 @@ ev_print_operation_set_job_name (EvPrint
96292f
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
96292f
 
96292f
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
96292f
+	g_return_if_fail (class != NULL);
96292f
 	g_return_if_fail (job_name != NULL);
96292f
 
96292f
 	class->set_job_name (op, job_name);
96292f
@@ -260,6 +266,7 @@ ev_print_operation_get_job_name (EvPrint
96292f
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
96292f
 
96292f
 	g_return_val_if_fail (EV_IS_PRINT_OPERATION (op), NULL);
96292f
+	g_return_val_if_fail (class != NULL, NULL);
96292f
 
96292f
 	return class->get_job_name (op);
96292f
 }
96292f
@@ -271,6 +278,7 @@ ev_print_operation_run (EvPrintOperation
96292f
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
96292f
 
96292f
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
96292f
+	g_return_if_fail (class != NULL);
96292f
 
96292f
 	class->run (op, parent);
96292f
 }
96292f
@@ -281,6 +289,7 @@ ev_print_operation_cancel (EvPrintOperat
96292f
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
96292f
 
96292f
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
96292f
+	g_return_if_fail (class != NULL);
96292f
 
96292f
 	class->cancel (op);
96292f
 }
96292f
@@ -292,6 +301,7 @@ ev_print_operation_get_error (EvPrintOpe
96292f
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
96292f
 
96292f
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
96292f
+	g_return_if_fail (class != NULL);
96292f
 
96292f
 	class->get_error (op, error);
96292f
 }
96292f
@@ -303,6 +313,7 @@ ev_print_operation_set_embed_page_setup
96292f
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
96292f
 
96292f
 	g_return_if_fail (EV_IS_PRINT_OPERATION (op));
96292f
+	g_return_if_fail (class != NULL);
96292f
 
96292f
 	class->set_embed_page_setup (op, embed);
96292f
 }
96292f
@@ -313,6 +324,7 @@ ev_print_operation_get_embed_page_setup
96292f
 	EvPrintOperationClass *class = EV_PRINT_OPERATION_GET_CLASS (op);
96292f
 
96292f
 	g_return_val_if_fail (EV_IS_PRINT_OPERATION (op), FALSE);
96292f
+	g_return_val_if_fail (class != NULL, FALSE);
96292f
 
96292f
 	return class->get_embed_page_setup (op);
96292f
 }
96292f
--- evince-40.1/libview/ev-timeline.c
96292f
+++ evince-40.1/libview/ev-timeline.c
96292f
@@ -289,9 +289,15 @@ ev_timeline_new (guint duration)
96292f
 void
96292f
 ev_timeline_start (EvTimeline *timeline)
96292f
 {
96292f
+	EvTimelineClass *klass;
96292f
+
96292f
 	g_return_if_fail (EV_IS_TIMELINE (timeline));
96292f
 
96292f
-	EV_TIMELINE_GET_CLASS (timeline)->start (timeline);
96292f
+	klass = EV_TIMELINE_GET_CLASS (timeline);
96292f
+
96292f
+	g_return_if_fail (klass != NULL);
96292f
+
96292f
+	klass->start (timeline);
96292f
 }
96292f
 
96292f
 void
96292f
--- evince-40.1/libview/ev-view.c
96292f
+++ evince-40.1/libview/ev-view.c
96292f
@@ -1147,7 +1147,7 @@ ensure_rectangle_is_visible (EvView *vie
96292f
 	if (rect->x < adj_value) {
96292f
 		value = MAX (gtk_adjustment_get_lower (adjustment), rect->x - MARGIN);
96292f
 		gtk_adjustment_set_value (view->hadjustment, value);
96292f
-	} else if (rect->x + rect->height > adj_value + allocation.width) {
96292f
+	} else if (rect->x + rect->width > adj_value + allocation.width) {
96292f
 		value = MIN (gtk_adjustment_get_upper (adjustment), rect->x + rect->width -
96292f
 			     allocation.width + MARGIN);
96292f
 		gtk_adjustment_set_value (view->hadjustment, value);
96292f
@@ -1777,6 +1777,11 @@ goto_fitv_dest (EvView *view, EvLinkDest
96292f
 
96292f
 	page = ev_link_dest_get_page (dest);
96292f
 
96292f
+	if (page < 0) {
96292f
+		g_warning ("Link does not contain a page.");
96292f
+		return;
96292f
+	}
96292f
+
96292f
 	left = ev_link_dest_get_left (dest, &change_left);
96292f
 	doc_point.x = change_left ? left : 0;
96292f
 	doc_point.y = 0;
96292f
@@ -1813,6 +1818,11 @@ goto_fith_dest (EvView *view, EvLinkDest
96292f
 
96292f
 	page = ev_link_dest_get_page (dest);
96292f
 
96292f
+	if (page < 0) {
96292f
+		g_warning ("Link does not contain a page.");
96292f
+		return;
96292f
+	}
96292f
+
96292f
 	top = ev_link_dest_get_top (dest, &change_top);
96292f
 	doc_point.x = 0;
96292f
 	doc_point.y = change_top ? top : 0;
96292f
@@ -1846,6 +1856,11 @@ goto_fit_dest (EvView *view, EvLinkDest
96292f
 
96292f
 	page = ev_link_dest_get_page (dest);
96292f
 
96292f
+	if (page < 0) {
96292f
+		g_warning ("Link does not contain a page.");
96292f
+		return;
96292f
+	}
96292f
+
96292f
 	if (view->allow_links_change_zoom) {
96292f
 		double zoom;
96292f
 		gdouble doc_width, doc_height;
96292f
--- evince-40.1/libview/ev-view-presentation.c
96292f
+++ evince-40.1/libview/ev-view-presentation.c
96292f
@@ -448,7 +448,7 @@ ev_view_presentation_update_current_page
96292f
 {
96292f
 	gint jump;
96292f
 
96292f
-	if (page < 0 || page >= ev_document_get_n_pages (pview->document))
96292f
+	if (page >= ev_document_get_n_pages (pview->document))
96292f
 		return;
96292f
 
96292f
 	ev_view_presentation_animation_cancel (pview);
96292f
--- evince-40.1/shell/ev-find-sidebar.c
96292f
+++ evince-40.1/shell/ev-find-sidebar.c
96292f
@@ -476,8 +476,10 @@ process_matches_idle (EvFindSidebar *sid
96292f
 		page_label = ev_document_get_page_label (document, current_page);
96292f
                 page_text = get_page_text (document, page, &areas, &n_areas);
96292f
                 g_object_unref (page);
96292f
-                if (!page_text)
96292f
+                if (!page_text) {
96292f
+                        g_free (page_label);
96292f
                         continue;
96292f
+                }
96292f
 
96292f
                 text_log_attrs_length = g_utf8_strlen (page_text, -1);
96292f
                 text_log_attrs = g_new0 (PangoLogAttr, text_log_attrs_length + 1);
96292f
--- evince-40.1/shell/ev-sidebar-thumbnails.c
96292f
+++ evince-40.1/shell/ev-sidebar-thumbnails.c
96292f
@@ -658,11 +658,11 @@ ev_sidebar_thumbnails_fill_model (EvSide
96292f
 	int i;
96292f
 	gint prev_width = -1;
96292f
 	gint prev_height = -1;
96292f
+	cairo_surface_t *loading_icon = NULL;
96292f
 
96292f
 	for (i = 0; i < sidebar_thumbnails->priv->n_pages; i++) {
96292f
 		gchar     *page_label;
96292f
 		gchar     *page_string;
96292f
-		cairo_surface_t *loading_icon = NULL;
96292f
 		gint       width, height;
96292f
 
96292f
 		page_label = ev_document_get_page_label (priv->document, i);
96292f
--- evince-40.1/shell/ev-window.c
96292f
+++ evince-40.1/shell/ev-window.c
96292f
@@ -3121,10 +3121,10 @@ ev_window_load_print_settings_from_metad
96292f
 	for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
96292f
 		gchar *value = NULL;
96292f
 
96292f
-		ev_metadata_get_string (priv->metadata,
96292f
-					document_print_settings[i], &value);
96292f
-		gtk_print_settings_set (print_settings,
96292f
-					document_print_settings[i], value);
96292f
+		if (ev_metadata_get_string (priv->metadata,
96292f
+					    document_print_settings[i], &value))
96292f
+			gtk_print_settings_set (print_settings,
96292f
+						document_print_settings[i], value);
96292f
 	}
96292f
 }
96292f
 
96292f
@@ -4705,12 +4705,16 @@ ev_window_cmd_bookmarks_add (GSimpleActi
96292f
 	gchar     *page_label;
96292f
 
96292f
 	bm.page = ev_document_model_get_page (priv->model);
96292f
-	page_label = ev_document_get_page_label (priv->document, bm.page);
96292f
-	bm.title = g_strdup_printf (_("Page %s"), page_label);
96292f
-	g_free (page_label);
96292f
+	if (bm.page >= 0) {
96292f
+		page_label = ev_document_get_page_label (priv->document, bm.page);
96292f
+		bm.title = g_strdup_printf (_("Page %s"), page_label);
96292f
+		g_free (page_label);
96292f
 
96292f
-	/* EvBookmarks takes ownership of bookmark */
96292f
-	ev_bookmarks_add (priv->bookmarks, &bm;;
96292f
+		/* EvBookmarks takes ownership of bookmark */
96292f
+		ev_bookmarks_add (priv->bookmarks, &bm;;
96292f
+	} else {
96292f
+		g_warning ("Bookmarking of a page failed.");
96292f
+	}
96292f
 }
96292f
 
96292f
 static void