[glib: 15/16] glib: Port various callers to use g_utf8_validate_len()



commit 1c421b0158abb5634e0a38c02860f396f2063e1b
Author: Philip Withnall <withnall endlessm com>
Date:   Thu Oct 4 13:22:13 2018 +0100

    glib: Port various callers to use g_utf8_validate_len()
    
    These were callers which explicitly specified the string length to
    g_utf8_validate(), when it couldn’t be negative, and hence should be
    able to unconditionally benefit from the increased string handling
    length.
    
    At least one call site would have previously silently changed behaviour
    if called with strings longer than G_MAXSSIZE in length.
    
    Another call site was passing strlen(string) to g_utf8_validate(), which
    seems pointless: just pass -1 instead, and let g_utf8_validate()
    calculate the string length. Its behaviour on embedded nul bytes
    wouldn’t change, as strlen() stops at the first one.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 gio/glocalfileinfo.c | 4 ++--
 glib/giochannel.c    | 2 +-
 glib/gmarkup.c       | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c
index ed7e99400..59cfb9ba9 100644
--- a/gio/glocalfileinfo.c
+++ b/gio/glocalfileinfo.c
@@ -1063,7 +1063,7 @@ make_valid_utf8 (const char *name)
 {
   GString *string;
   const gchar *remainder, *invalid;
-  gint remaining_bytes, valid_bytes;
+  gsize remaining_bytes, valid_bytes;
   
   string = NULL;
   remainder = name;
@@ -1071,7 +1071,7 @@ make_valid_utf8 (const char *name)
   
   while (remaining_bytes != 0) 
     {
-      if (g_utf8_validate (remainder, remaining_bytes, &invalid)) 
+      if (g_utf8_validate_len (remainder, remaining_bytes, &invalid))
        break;
       valid_bytes = invalid - remainder;
     
diff --git a/glib/giochannel.c b/glib/giochannel.c
index d8c3b0b09..88fd8c81d 100644
--- a/glib/giochannel.c
+++ b/glib/giochannel.c
@@ -2323,7 +2323,7 @@ reconvert:
 
               /* UTF-8, just validate, emulate g_iconv */
 
-              if (!g_utf8_validate (from_buf, try_len, &badchar))
+              if (!g_utf8_validate_len (from_buf, try_len, &badchar))
                 {
                   gunichar try_char;
                   gsize incomplete_len = from_buf + try_len - badchar;
diff --git a/glib/gmarkup.c b/glib/gmarkup.c
index 43bb0c7f8..9b15b1281 100644
--- a/glib/gmarkup.c
+++ b/glib/gmarkup.c
@@ -455,7 +455,7 @@ slow_name_validate (GMarkupParseContext  *context,
 {
   const gchar *p = name;
 
-  if (!g_utf8_validate (name, strlen (name), NULL))
+  if (!g_utf8_validate (name, -1, NULL))
     {
       set_error (context, error, G_MARKUP_ERROR_BAD_UTF8,
                  _("Invalid UTF-8 encoded text in name — not valid “%s”"), name);
@@ -538,7 +538,7 @@ text_validate (GMarkupParseContext  *context,
                gint                  len,
                GError              **error)
 {
-  if (!g_utf8_validate (p, len, NULL))
+  if (!g_utf8_validate_len (p, len, NULL))
     {
       set_error (context, error, G_MARKUP_ERROR_BAD_UTF8,
                  _("Invalid UTF-8 encoded text in name — not valid “%s”"), p);


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