[glib/glib-2-58: 15/21] glib: Port various callers to use g_utf8_validate_len()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-58: 15/21] glib: Port various callers to use g_utf8_validate_len()
- Date: Tue, 6 Nov 2018 13:11:04 +0000 (UTC)
commit f998b28cde63d0c2e7373f0a6f8097c7c417a022
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 | 2 +-
glib/giochannel.c | 3 ++-
glib/gmarkup.c | 5 +++--
glib/gvariant-serialiser.c | 3 ++-
4 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c
index ed7e99400..4d2be7208 100644
--- a/gio/glocalfileinfo.c
+++ b/gio/glocalfileinfo.c
@@ -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 (remainder, remaining_bytes, &invalid))
break;
valid_bytes = invalid - remainder;
diff --git a/glib/giochannel.c b/glib/giochannel.c
index d8c3b0b09..43c6a935b 100644
--- a/glib/giochannel.c
+++ b/glib/giochannel.c
@@ -39,6 +39,7 @@
#include "gstrfuncs.h"
#include "gtestutils.h"
#include "glibintl.h"
+#include "gunicodeprivate.h"
/**
@@ -2323,7 +2324,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 f1ab94e56..bcb91c0a4 100644
--- a/glib/gmarkup.c
+++ b/glib/gmarkup.c
@@ -35,6 +35,7 @@
#include "gtestutils.h"
#include "glibintl.h"
#include "gthread.h"
+#include "gunicodeprivate.h"
/**
* SECTION:markup
@@ -455,7 +456,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 +539,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);
diff --git a/glib/gvariant-serialiser.c b/glib/gvariant-serialiser.c
index ccf96b4aa..c6e400b53 100644
--- a/glib/gvariant-serialiser.c
+++ b/glib/gvariant-serialiser.c
@@ -22,6 +22,7 @@
#include "config.h"
#include "gvariant-serialiser.h"
+#include "gunicodeprivate.h"
#include <glib/gvariant-internal.h>
#include <glib/gtestutils.h>
@@ -1652,7 +1653,7 @@ g_variant_serialiser_is_string (gconstpointer data,
if (*expected_end != '\0')
return FALSE;
- g_utf8_validate_len (data, size, &end);
+ _g_utf8_validate_len (data, size, &end);
return end == expected_end;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]