[gimp] libgimpbase: improve gimp_parasite_get_data().
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimpbase: improve gimp_parasite_get_data().
- Date: Fri, 29 Jan 2021 22:53:35 +0000 (UTC)
commit 443b738e61d89b7007856ac19d3faa2e0aef4205
Author: Jehan <jehan girinstud io>
Date: Fri Jan 29 23:38:08 2021 +0100
libgimpbase: improve gimp_parasite_get_data().
Allow @num_bytes to be nullable, but add text in the documentation that
this is only useful when you want to check if there is contents.
Also make @num_bytes into a guint32, and finally set it to 0 when there
is no parasite.
libgimpbase/gimpparasite.c | 16 +++++++++++++---
libgimpbase/gimpparasite.h | 2 +-
2 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/libgimpbase/gimpparasite.c b/libgimpbase/gimpparasite.c
index acdf2f4a6b..11bd13895b 100644
--- a/libgimpbase/gimpparasite.c
+++ b/libgimpbase/gimpparasite.c
@@ -447,23 +447,33 @@ gimp_parasite_data_size (const GimpParasite *parasite)
/**
* gimp_parasite_get_data:
* @parasite: a #GimpParasite
- * @num_bytes: (out): size of the returned data.
+ * @num_bytes: (out) (nullable): size of the returned data.
*
* Gets the parasite's data. It may not necessarily be text, nor is it
* guaranteed to be %NULL-terminated. It is your responsibility to know
* how to deal with this data.
+ * Even when you expect a nul-terminated string, it is advised not to
+ * assume the returned data to be, as parasites can be edited by third
+ * party scripts. You may end up reading out-of-bounds data. So you
+ * should only ignore @num_bytes when you all you care about is checking
+ * if the parasite has contents.
*
* Returns: (array length=num_bytes) (element-type char): parasite's data.
*/
gconstpointer
gimp_parasite_get_data (const GimpParasite *parasite,
- gint *num_bytes)
+ guint32 *num_bytes)
{
if (parasite)
{
- *num_bytes = parasite->size;
+ if (num_bytes)
+ *num_bytes = parasite->size;
+
return parasite->data;
}
+ if (num_bytes)
+ *num_bytes = 0;
+
return NULL;
}
diff --git a/libgimpbase/gimpparasite.h b/libgimpbase/gimpparasite.h
index 25ba74be56..617c726131 100644
--- a/libgimpbase/gimpparasite.h
+++ b/libgimpbase/gimpparasite.h
@@ -110,7 +110,7 @@ gconstpointer gimp_parasite_data (const GimpParasite *parasite);
glong gimp_parasite_data_size (const GimpParasite *parasite);
gconstpointer gimp_parasite_get_data (const GimpParasite *parasite,
- gint *num_bytes);
+ guint32 *num_bytes);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]