[gimp] libgimp, libgimpconfig: use gimp_parasite_get_data().
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimp, libgimpconfig: use gimp_parasite_get_data().
- Date: Sat, 30 Jan 2021 09:18:17 +0000 (UTC)
commit 3e4407a315a74e11ecc0b47ada33dd98309bf381
Author: Jehan <jehan girinstud io>
Date: Sat Jan 30 08:57:43 2021 +0100
libgimp, libgimpconfig: use gimp_parasite_get_data().
As previously do not trust that parasite contents is proper text ending
with nul character by always using the parasite size info.
libgimp/gimpimagemetadata-save.c | 31 +++++++++++++++++++------------
libgimp/gimpprocedureconfig.c | 13 ++++++++-----
libgimpconfig/gimpconfig-iface.c | 13 +++++++------
3 files changed, 34 insertions(+), 23 deletions(-)
---
diff --git a/libgimp/gimpimagemetadata-save.c b/libgimp/gimpimagemetadata-save.c
index 3781d732d6..f84763c5d8 100644
--- a/libgimp/gimpimagemetadata-save.c
+++ b/libgimp/gimpimagemetadata-save.c
@@ -83,16 +83,16 @@ gimp_image_metadata_save_prepare (GimpImage *image,
if (metadata)
{
- GDateTime *datetime;
- const GimpParasite *comment_parasite;
- const gchar *comment = NULL;
- gint image_width;
- gint image_height;
- gdouble xres;
- gdouble yres;
- gchar buffer[32];
- gchar *str;
- GExiv2Metadata *g2metadata = GEXIV2_METADATA (metadata);
+ GDateTime *datetime;
+ GimpParasite *comment_parasite;
+ gchar *comment = NULL;
+ gint image_width;
+ gint image_height;
+ gdouble xres;
+ gdouble yres;
+ gchar buffer[32];
+ gchar *str;
+ GExiv2Metadata *g2metadata = GEXIV2_METADATA (metadata);
image_width = gimp_image_width (image);
image_height = gimp_image_height (image);
@@ -101,7 +101,14 @@ gimp_image_metadata_save_prepare (GimpImage *image,
comment_parasite = gimp_image_get_parasite (image, "gimp-comment");
if (comment_parasite)
- comment = gimp_parasite_data (comment_parasite);
+ {
+ guint32 parasite_size;
+
+ comment = (gchar *) gimp_parasite_get_data (comment_parasite, ¶site_size);
+ comment = g_strndup (comment, parasite_size);
+
+ gimp_parasite_free (comment_parasite);
+ }
/* Exif */
@@ -198,7 +205,7 @@ gimp_image_metadata_save_prepare (GimpImage *image,
g_free (str);
g_date_time_unref (datetime);
-
+ g_clear_pointer (&comment, g_free);
}
else
{
diff --git a/libgimp/gimpprocedureconfig.c b/libgimp/gimpprocedureconfig.c
index 5a80bddaf9..0de75f6ed4 100644
--- a/libgimp/gimpprocedureconfig.c
+++ b/libgimp/gimpprocedureconfig.c
@@ -326,8 +326,10 @@ gimp_procedure_config_get_parasite (GimpProcedureConfig *config,
if (parasite)
{
- value = g_strndup (gimp_parasite_data (parasite),
- gimp_parasite_data_size (parasite));
+ guint32 parasite_size;
+
+ value = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
+ value = g_strndup (value, parasite_size);
gimp_parasite_free (parasite);
if (value && ! strlen (value))
@@ -374,10 +376,11 @@ gimp_procedure_config_set_parasite (GimpProcedureConfig *config,
/* it there is a parasite, always override it if its value was
* changed
*/
- gchar *image_value;
+ gchar *image_value;
+ guint32 parasite_size;
- image_value = g_strndup (gimp_parasite_data (parasite),
- gimp_parasite_data_size (parasite));
+ image_value = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
+ image_value = g_strndup (image_value, parasite_size);
gimp_parasite_free (parasite);
if (g_strcmp0 (value, image_value))
diff --git a/libgimpconfig/gimpconfig-iface.c b/libgimpconfig/gimpconfig-iface.c
index 7733b5e392..9c60b18faa 100644
--- a/libgimpconfig/gimpconfig-iface.c
+++ b/libgimpconfig/gimpconfig-iface.c
@@ -623,18 +623,19 @@ gimp_config_deserialize_parasite (GimpConfig *config,
gpointer data,
GError **error)
{
+ const gchar *parasite_data;
+ guint32 parasite_size;
+
g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE);
g_return_val_if_fail (parasite != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- if (! gimp_parasite_data (parasite))
+ parasite_data = gimp_parasite_get_data (parasite, ¶site_size);
+ if (! parasite_data)
return TRUE;
- return gimp_config_deserialize_string (config,
- gimp_parasite_data (parasite),
- gimp_parasite_data_size (parasite),
- data,
- error);
+ return gimp_config_deserialize_string (config, parasite_data, parasite_size,
+ data, error);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]