[glib: 1/2] gvariant: Fix documentation for g_variant_get_string() to match reality



commit 1519962792bc10c55993e5d0afe5103e1b56bf55
Author: Philip Withnall <withnall endlessm com>
Date:   Fri Jun 12 12:48:53 2020 +0100

    gvariant: Fix documentation for g_variant_get_string() to match reality
    
    The implementation didn’t match the documentation. The implementation
    has the right behaviour (wrt not allowing embedded nuls, validating
    UTF-8, and returning a default value if an invalid string is detected),
    so keep that and fix the documentation to match.
    
    The [`GVariant`
    specification](https://people.gnome.org/~desrt/gvariant-serialisation.pdf)
    is incorrect on this point, and the implementation of GLib was
    purposefully changed after the specification was published (but before
    `GVariant` became API-stable in GLib). The behaviour in GLib
    (specifically concerning all strings being in UTF-8) is consistent with
    D-Bus.
    
    Spotted by William Manley.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 glib/gvariant.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/glib/gvariant.c b/glib/gvariant.c
index 1e524801a..2d3717a7c 100644
--- a/glib/gvariant.c
+++ b/glib/gvariant.c
@@ -1440,11 +1440,15 @@ g_variant_is_signature (const gchar *string)
  * type.  This includes the types %G_VARIANT_TYPE_STRING,
  * %G_VARIANT_TYPE_OBJECT_PATH and %G_VARIANT_TYPE_SIGNATURE.
  *
- * The string will always be UTF-8 encoded, and will never be %NULL.
+ * The string will always be UTF-8 encoded, will never be %NULL, and will never
+ * contain nul bytes.
  *
  * If @length is non-%NULL then the length of the string (in bytes) is
  * returned there.  For trusted values, this information is already
- * known.  For untrusted values, a strlen() will be performed.
+ * known.  Untrusted values will be validated and, if valid, a strlen() will be
+ * performed. If invalid, a default value will be returned — for
+ * %G_VARIANT_TYPE_OBJECT_PATH, this is `"/"`, and for other types it is the
+ * empty string.
  *
  * It is an error to call this function with a @value of any type
  * other than those three.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]