[poppler] glib/demo glib/poppler-document.cc

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Thu Sep 23 05:12:19 PDT 2010


 glib/demo/info.cc        |    8 ++++++--
 glib/poppler-document.cc |   33 ++++++++++++++-------------------
 2 files changed, 20 insertions(+), 21 deletions(-)

New commits:
commit 721da3d542ab9b234b058f3c14ea9303d748107e
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Thu Sep 23 14:09:11 2010 +0200

    [glib] Use g_memdup instead of g_strdup in poppler_document_get_id()
    
    Ids are not null-terminated strings, but fixed size byte arrays.

diff --git a/glib/demo/info.cc b/glib/demo/info.cc
index 98c3015..930f2be 100644
--- a/glib/demo/info.cc
+++ b/glib/demo/info.cc
@@ -214,10 +214,14 @@ pgd_info_create_widget (PopplerDocument *document)
 	pgd_table_add_property (GTK_TABLE (table), "<b>Page Layout:</b>", enum_value->value_name, &row);
 
 	if (poppler_document_get_id (document, &perm_id, &up_id)) {
-		pgd_table_add_property (GTK_TABLE (table), "<b>Permanent ID:</b>", perm_id, &row);
-		pgd_table_add_property (GTK_TABLE (table), "<b>Update ID:</b>", up_id, &row);
+		str = g_strndup (perm_id, 32);
 		g_free (perm_id);
+		pgd_table_add_property (GTK_TABLE (table), "<b>Permanent ID:</b>", str, &row);
+		g_free (str);
+		str = g_strndup (up_id, 32);
 		g_free (up_id);
+		pgd_table_add_property (GTK_TABLE (table), "<b>Update ID:</b>", str, &row);
+		g_free (str);
 	}
 
 	pgd_info_add_permissions (GTK_TABLE (table), permissions, &row);
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index 6dd60bf..e3bda12 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -364,12 +364,15 @@ poppler_document_finalize (GObject *object)
  * @permanent_id: (out) (allow-none): location to store an allocated string, use g_free() to free the returned string
  * @update_id: (out) (allow-none): location to store an allocated string, use g_free() to free the returned string
  *
- * Returns the PDF file identifier represented as two byte string arrays.
+ * Returns the PDF file identifier represented as two byte string arrays of size 32.
  * @permanent_id is the permanent identifier that is built based on the file
  * contents at the time it was originally created, so that this identifer
  * never changes. @update_id is the update identifier that is built based on
  * the file contents at the time it was last updated.
  *
+ * Note that returned strings are not null-terminated, they have a fixed
+ * size of 32 bytes.
+ *
  * Returns: %TRUE if the @document contains an id, %FALSE otherwise
  *
  * Since: 0.16
@@ -379,34 +382,26 @@ poppler_document_get_id (PopplerDocument *document,
 			 gchar          **permanent_id,
 			 gchar          **update_id)
 {
-  GooString *permanent = NULL;
-  GooString *update = NULL;
-  gboolean   retval = FALSE;
+  GooString permanent;
+  GooString update;
+  gboolean  retval = FALSE;
 
   g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), FALSE);
 
-  if (permanent_id) {
-    permanent = new GooString();
+  if (permanent_id)
     *permanent_id = NULL;
-  }
-
-  if (update_id) {
-    update = new GooString();
+  if (update_id)
     *update_id = NULL;
-  }
 
-  if (document->doc->getID (permanent, update)) {
-    if (permanent)
-      *permanent_id = g_strdup (permanent->getCString());
-    if (update)
-      *update_id = g_strdup (update->getCString());
+  if (document->doc->getID (permanent_id ? &permanent : NULL, update_id ? &update : NULL)) {
+    if (permanent_id)
+      *permanent_id = (gchar *)g_memdup (permanent.getCString(), 32);
+    if (update_id)
+      *update_id = (gchar *)g_memdup (update.getCString(), 32);
 
     retval = TRUE;
   }
 
-  delete permanent;
-  delete update;
-
   return retval;
 }
 


More information about the poppler mailing list