Clarify the behaviour is max_len is zero. (#400044, Benjamin Dauvergne)
authorMatthias Clasen <mclasen@redhat.com>
Wed, 24 Jan 2007 04:38:57 +0000 (04:38 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Wed, 24 Jan 2007 04:38:57 +0000 (04:38 +0000)
2007-01-23  Matthias Clasen  <mclasen@redhat.com>

        * glib/gutf8.c (g_utf8_get_char_validated): Clarify
        the behaviour is max_len is zero.  (#400044,
        Benjamin Dauvergne)

svn path=/trunk/; revision=5311

ChangeLog
glib/gutf8.c

index 20bf7c102b9593e333aa7cb8af26a873dc13d5dd..5b22e1841a0e6a5652b00b5ad8a8d10b7df068bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-01-23  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/gutf8.c (g_utf8_get_char_validated): Clarify
+       the behaviour is max_len is zero.  (#400044, 
+       Benjamin Dauvergne)
+
 2007-01-23  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/goption.c (print_help): Use bitwise &
index 4b91334e02bd49b9b904cdd9ba98b58db965d31e..6d9850273fda6cbf9bfdc3f14afed6bf74ebbf8d 100644 (file)
@@ -764,14 +764,20 @@ g_utf8_get_char_extended (const  gchar *p,
  * 
  * Return value: the resulting character. If @p points to a partial
  *    sequence at the end of a string that could begin a valid 
- *    character, returns (gunichar)-2; otherwise, if @p does not point 
- *    to a valid UTF-8 encoded Unicode character, returns (gunichar)-1.
+ *    character (or if @max_len is zero), returns (gunichar)-2; 
+ *    otherwise, if @p does not point to a valid UTF-8 encoded 
+ *    Unicode character, returns (gunichar)-1.
  **/
 gunichar
 g_utf8_get_char_validated (const  gchar *p,
                           gssize max_len)
 {
-  gunichar result = g_utf8_get_char_extended (p, max_len);
+  gunichar result;
+
+  if (max_len == 0)
+    return (gunichar)-2;
+
+  result = g_utf8_get_char_extended (p, max_len);
 
   if (result & 0x80000000)
     return result;