mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-20 15:48:54 +02:00
Merge branch '3527-Wshorten-64-to-32' into 'main'
Fix various -Wshorten-64-to-32 warnings See merge request GNOME/glib!4387
This commit is contained in:
@@ -129,7 +129,7 @@ journal_stream_fd (const char *identifier,
|
|||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
salen = offsetof (struct sockaddr_un, sun_path) + strlen (sa.un.sun_path) + 1;
|
salen = offsetof (struct sockaddr_un, sun_path) + (socklen_t) strlen (sa.un.sun_path) + 1;
|
||||||
|
|
||||||
if (connect (fd, &sa.sa, salen) < 0)
|
if (connect (fd, &sa.sa, salen) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
#include "gmessages.h"
|
#include "gmessages.h"
|
||||||
#include "gstring.h"
|
#include "gstring.h"
|
||||||
#include "gstrfuncs.h"
|
#include "gstrfuncs.h"
|
||||||
|
#include "gtestutils.h"
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
|
|
||||||
#ifdef G_PLATFORM_WIN32
|
#ifdef G_PLATFORM_WIN32
|
||||||
@@ -208,7 +209,7 @@ punycode_encode (const gchar *input_utf8,
|
|||||||
*/
|
*/
|
||||||
static gchar *
|
static gchar *
|
||||||
remove_junk (const gchar *str,
|
remove_junk (const gchar *str,
|
||||||
gint len)
|
gssize len)
|
||||||
{
|
{
|
||||||
GString *cleaned = NULL;
|
GString *cleaned = NULL;
|
||||||
const gchar *p;
|
const gchar *p;
|
||||||
@@ -237,7 +238,7 @@ remove_junk (const gchar *str,
|
|||||||
|
|
||||||
static inline gboolean
|
static inline gboolean
|
||||||
contains_uppercase_letters (const gchar *str,
|
contains_uppercase_letters (const gchar *str,
|
||||||
gint len)
|
gssize len)
|
||||||
{
|
{
|
||||||
const gchar *p;
|
const gchar *p;
|
||||||
|
|
||||||
@@ -251,7 +252,7 @@ contains_uppercase_letters (const gchar *str,
|
|||||||
|
|
||||||
static inline gboolean
|
static inline gboolean
|
||||||
contains_non_ascii (const gchar *str,
|
contains_non_ascii (const gchar *str,
|
||||||
gint len)
|
gssize len)
|
||||||
{
|
{
|
||||||
const gchar *p;
|
const gchar *p;
|
||||||
|
|
||||||
@@ -298,10 +299,11 @@ idna_is_prohibited (gunichar ch)
|
|||||||
/* RFC 3491 IDN cleanup algorithm. */
|
/* RFC 3491 IDN cleanup algorithm. */
|
||||||
static gchar *
|
static gchar *
|
||||||
nameprep (const gchar *hostname,
|
nameprep (const gchar *hostname,
|
||||||
gint len,
|
gssize len,
|
||||||
gboolean *is_unicode)
|
gboolean *is_unicode)
|
||||||
{
|
{
|
||||||
gchar *name, *tmp = NULL, *p;
|
const char *name, *p;
|
||||||
|
char *name_owned = NULL, *name_normalized = NULL;
|
||||||
|
|
||||||
/* It would be nice if we could do this without repeatedly
|
/* It would be nice if we could do this without repeatedly
|
||||||
* allocating strings and converting back and forth between
|
* allocating strings and converting back and forth between
|
||||||
@@ -311,21 +313,20 @@ nameprep (const gchar *hostname,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Remove presentation-only characters */
|
/* Remove presentation-only characters */
|
||||||
name = remove_junk (hostname, len);
|
name = name_owned = remove_junk (hostname, len);
|
||||||
if (name)
|
if (name)
|
||||||
{
|
len = -1;
|
||||||
tmp = name;
|
|
||||||
len = -1;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
name = (gchar *)hostname;
|
name = hostname;
|
||||||
|
|
||||||
/* Convert to lowercase */
|
/* Convert to lowercase */
|
||||||
if (contains_uppercase_letters (name, len))
|
if (contains_uppercase_letters (name, len))
|
||||||
{
|
{
|
||||||
name = g_utf8_strdown (name, len);
|
char *name_owned_lower = NULL;
|
||||||
g_free (tmp);
|
|
||||||
tmp = name;
|
name = name_owned_lower = g_utf8_strdown (name, len);
|
||||||
|
g_free (name_owned);
|
||||||
|
name_owned = g_steal_pointer (&name_owned_lower);
|
||||||
len = -1;
|
len = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,18 +334,19 @@ nameprep (const gchar *hostname,
|
|||||||
if (!contains_non_ascii (name, len))
|
if (!contains_non_ascii (name, len))
|
||||||
{
|
{
|
||||||
*is_unicode = FALSE;
|
*is_unicode = FALSE;
|
||||||
if (name == (gchar *)hostname)
|
if (name == hostname)
|
||||||
return len == -1 ? g_strdup (hostname) : g_strndup (hostname, len);
|
return len == -1 ? g_strdup (hostname) : g_strndup (hostname, len);
|
||||||
else
|
else
|
||||||
return name;
|
return g_steal_pointer (&name_owned);
|
||||||
}
|
}
|
||||||
|
|
||||||
*is_unicode = TRUE;
|
*is_unicode = TRUE;
|
||||||
|
|
||||||
/* Normalize */
|
/* Normalize */
|
||||||
name = g_utf8_normalize (name, len, G_NORMALIZE_NFKC);
|
name = name_normalized = g_utf8_normalize (name, len, G_NORMALIZE_NFKC);
|
||||||
g_free (tmp);
|
g_free (name_owned);
|
||||||
tmp = name;
|
name_owned = g_steal_pointer (&name_normalized);
|
||||||
|
len = -1;
|
||||||
|
|
||||||
if (!name)
|
if (!name)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -356,11 +358,14 @@ nameprep (const gchar *hostname,
|
|||||||
* same as tolower(nfkc(X)), then we could skip the first tolower,
|
* same as tolower(nfkc(X)), then we could skip the first tolower,
|
||||||
* but I'm not sure it is.)
|
* but I'm not sure it is.)
|
||||||
*/
|
*/
|
||||||
if (contains_uppercase_letters (name, -1))
|
if (contains_uppercase_letters (name, len))
|
||||||
{
|
{
|
||||||
name = g_utf8_strdown (name, -1);
|
char *name_owned_lower = NULL;
|
||||||
g_free (tmp);
|
|
||||||
tmp = name;
|
name = name_owned_lower = g_utf8_strdown (name, len);
|
||||||
|
g_free (name_owned);
|
||||||
|
name_owned = g_steal_pointer (&name_owned_lower);
|
||||||
|
len = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for prohibited characters */
|
/* Check for prohibited characters */
|
||||||
@@ -369,7 +374,8 @@ nameprep (const gchar *hostname,
|
|||||||
if (idna_is_prohibited (g_utf8_get_char (p)))
|
if (idna_is_prohibited (g_utf8_get_char (p)))
|
||||||
{
|
{
|
||||||
name = NULL;
|
name = NULL;
|
||||||
g_free (tmp);
|
g_clear_pointer (&name_owned, g_free);
|
||||||
|
len = -1;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -379,7 +385,7 @@ nameprep (const gchar *hostname,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
done:
|
done:
|
||||||
return name;
|
return g_steal_pointer (&name_owned);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* RFC 3490, section 3.1 says '.', 0x3002, 0xFF0E, and 0xFF61 count as
|
/* RFC 3490, section 3.1 says '.', 0x3002, 0xFF0E, and 0xFF61 count as
|
||||||
@@ -582,8 +588,10 @@ punycode_decode (const gchar *input,
|
|||||||
split--;
|
split--;
|
||||||
if (split > input)
|
if (split > input)
|
||||||
{
|
{
|
||||||
|
g_assert ((guint) (split - input) <= G_MAXUINT);
|
||||||
|
|
||||||
output_chars = g_array_sized_new (FALSE, FALSE, sizeof (gunichar),
|
output_chars = g_array_sized_new (FALSE, FALSE, sizeof (gunichar),
|
||||||
split - input);
|
(guint) (split - input));
|
||||||
input_length -= (split - input) + 1;
|
input_length -= (split - input) + 1;
|
||||||
while (input < split)
|
while (input < split)
|
||||||
{
|
{
|
||||||
|
@@ -234,7 +234,7 @@ GLogLevelFlags g_log_always_fatal = G_LOG_FATAL_MASK;
|
|||||||
static gboolean
|
static gboolean
|
||||||
debug_key_matches (const gchar *key,
|
debug_key_matches (const gchar *key,
|
||||||
const gchar *token,
|
const gchar *token,
|
||||||
guint length)
|
size_t length)
|
||||||
{
|
{
|
||||||
/* may not call GLib functions: see note in g_parse_debug_string() */
|
/* may not call GLib functions: see note in g_parse_debug_string() */
|
||||||
for (; length; length--, key++, token++)
|
for (; length; length--, key++, token++)
|
||||||
|
@@ -2397,7 +2397,7 @@ journal_sendv (struct iovec *iov,
|
|||||||
|
|
||||||
memset (&mh, 0, sizeof (mh));
|
memset (&mh, 0, sizeof (mh));
|
||||||
mh.msg_name = &sa;
|
mh.msg_name = &sa;
|
||||||
mh.msg_namelen = offsetof (struct sockaddr_un, sun_path) + strlen (sa.sun_path);
|
mh.msg_namelen = offsetof (struct sockaddr_un, sun_path) + (socklen_t) strlen (sa.sun_path);
|
||||||
mh.msg_iov = iov;
|
mh.msg_iov = iov;
|
||||||
mh.msg_iovlen = iovlen;
|
mh.msg_iovlen = iovlen;
|
||||||
|
|
||||||
|
@@ -513,7 +513,7 @@ g_option_context_add_main_entries (GOptionContext *context,
|
|||||||
g_option_group_set_translation_domain (context->main_group, translation_domain);
|
g_option_group_set_translation_domain (context->main_group, translation_domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static size_t
|
||||||
calculate_max_length (GOptionGroup *group,
|
calculate_max_length (GOptionGroup *group,
|
||||||
GHashTable *aliases)
|
GHashTable *aliases)
|
||||||
{
|
{
|
||||||
@@ -553,7 +553,7 @@ calculate_max_length (GOptionGroup *group,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
print_entry (GOptionGroup *group,
|
print_entry (GOptionGroup *group,
|
||||||
gint max_length,
|
size_t max_length,
|
||||||
const GOptionEntry *entry,
|
const GOptionEntry *entry,
|
||||||
GString *string,
|
GString *string,
|
||||||
GHashTable *aliases)
|
GHashTable *aliases)
|
||||||
@@ -601,7 +601,7 @@ group_has_visible_entries (GOptionContext *context,
|
|||||||
{
|
{
|
||||||
GOptionFlags reject_filter = G_OPTION_FLAG_HIDDEN;
|
GOptionFlags reject_filter = G_OPTION_FLAG_HIDDEN;
|
||||||
GOptionEntry *entry;
|
GOptionEntry *entry;
|
||||||
gint i, l;
|
size_t i, l;
|
||||||
gboolean main_group = group == context->main_group;
|
gboolean main_group = group == context->main_group;
|
||||||
|
|
||||||
if (!main_entries)
|
if (!main_entries)
|
||||||
@@ -691,7 +691,7 @@ g_option_context_get_help (GOptionContext *context,
|
|||||||
GOptionGroup *group)
|
GOptionGroup *group)
|
||||||
{
|
{
|
||||||
GList *list;
|
GList *list;
|
||||||
gint max_length = 0, len;
|
size_t max_length = 0, len;
|
||||||
gsize i;
|
gsize i;
|
||||||
GOptionEntry *entry;
|
GOptionEntry *entry;
|
||||||
GHashTable *shadow_map;
|
GHashTable *shadow_map;
|
||||||
@@ -833,6 +833,8 @@ g_option_context_get_help (GOptionContext *context,
|
|||||||
/* Add a bit of padding */
|
/* Add a bit of padding */
|
||||||
max_length += 4;
|
max_length += 4;
|
||||||
|
|
||||||
|
g_assert (max_length <= G_MAXINT);
|
||||||
|
|
||||||
if (!group && context->help_enabled)
|
if (!group && context->help_enabled)
|
||||||
{
|
{
|
||||||
list = context->groups;
|
list = context->groups;
|
||||||
@@ -840,13 +842,13 @@ g_option_context_get_help (GOptionContext *context,
|
|||||||
token = context_has_h_entry (context) ? '?' : 'h';
|
token = context_has_h_entry (context) ? '?' : 'h';
|
||||||
|
|
||||||
g_string_append_printf (string, "%s\n -%c, --%-*s %s\n",
|
g_string_append_printf (string, "%s\n -%c, --%-*s %s\n",
|
||||||
_("Help Options:"), token, max_length - 4, "help",
|
_("Help Options:"), token, (int) max_length - 4, "help",
|
||||||
_("Show help options"));
|
_("Show help options"));
|
||||||
|
|
||||||
/* We only want --help-all when there are groups */
|
/* We only want --help-all when there are groups */
|
||||||
if (list)
|
if (list)
|
||||||
g_string_append_printf (string, " --%-*s %s\n",
|
g_string_append_printf (string, " --%-*s %s\n",
|
||||||
max_length, "help-all",
|
(int) max_length, "help-all",
|
||||||
_("Show all help options"));
|
_("Show all help options"));
|
||||||
|
|
||||||
while (list)
|
while (list)
|
||||||
@@ -855,7 +857,7 @@ g_option_context_get_help (GOptionContext *context,
|
|||||||
|
|
||||||
if (group_has_visible_entries (context, g, FALSE))
|
if (group_has_visible_entries (context, g, FALSE))
|
||||||
g_string_append_printf (string, " --help-%-*s %s\n",
|
g_string_append_printf (string, " --help-%-*s %s\n",
|
||||||
max_length - 5, g->name,
|
(int) max_length - 5, g->name,
|
||||||
TRANSLATE (g, g->help_description));
|
TRANSLATE (g, g->help_description));
|
||||||
|
|
||||||
list = list->next;
|
list = list->next;
|
||||||
@@ -981,7 +983,7 @@ parse_int (const gchar *arg_name,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
*result = tmp;
|
*result = (int) tmp;
|
||||||
if (*result != tmp || errno == ERANGE)
|
if (*result != tmp || errno == ERANGE)
|
||||||
{
|
{
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
@@ -1810,7 +1812,7 @@ g_option_context_parse (GOptionContext *context,
|
|||||||
gchar ***argv,
|
gchar ***argv,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gint i, j, k;
|
gint i, k;
|
||||||
GList *list;
|
GList *list;
|
||||||
|
|
||||||
g_return_val_if_fail (context != NULL, FALSE);
|
g_return_val_if_fail (context != NULL, FALSE);
|
||||||
@@ -1959,13 +1961,14 @@ g_option_context_parse (GOptionContext *context,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ /* short option */
|
{ /* short option */
|
||||||
gint new_i = i, arg_length;
|
gint new_i = i;
|
||||||
|
size_t arg_length;
|
||||||
gboolean *nulled_out = NULL;
|
gboolean *nulled_out = NULL;
|
||||||
gboolean has_h_entry = context_has_h_entry (context);
|
gboolean has_h_entry = context_has_h_entry (context);
|
||||||
arg = (*argv)[i] + 1;
|
arg = (*argv)[i] + 1;
|
||||||
arg_length = strlen (arg);
|
arg_length = strlen (arg);
|
||||||
nulled_out = g_newa0 (gboolean, arg_length);
|
nulled_out = g_newa0 (gboolean, arg_length);
|
||||||
for (j = 0; j < arg_length; j++)
|
for (size_t j = 0; j < arg_length; j++)
|
||||||
{
|
{
|
||||||
if (context->help_enabled && (arg[j] == '?' ||
|
if (context->help_enabled && (arg[j] == '?' ||
|
||||||
(arg[j] == 'h' && !has_h_entry)))
|
(arg[j] == 'h' && !has_h_entry)))
|
||||||
@@ -2004,7 +2007,7 @@ g_option_context_parse (GOptionContext *context,
|
|||||||
{
|
{
|
||||||
gchar *new_arg = NULL;
|
gchar *new_arg = NULL;
|
||||||
gint arg_index = 0;
|
gint arg_index = 0;
|
||||||
for (j = 0; j < arg_length; j++)
|
for (size_t j = 0; j < arg_length; j++)
|
||||||
{
|
{
|
||||||
if (!nulled_out[j])
|
if (!nulled_out[j])
|
||||||
{
|
{
|
||||||
@@ -2093,7 +2096,7 @@ g_option_context_parse (GOptionContext *context,
|
|||||||
if (k > i)
|
if (k > i)
|
||||||
{
|
{
|
||||||
k -= i;
|
k -= i;
|
||||||
for (j = i + k; j < *argc; j++)
|
for (int j = i + k; j < *argc; j++)
|
||||||
{
|
{
|
||||||
(*argv)[j-k] = (*argv)[j];
|
(*argv)[j-k] = (*argv)[j];
|
||||||
(*argv)[j] = NULL;
|
(*argv)[j] = NULL;
|
||||||
|
@@ -289,12 +289,13 @@ g_pattern_spec_new (const gchar *pattern)
|
|||||||
{
|
{
|
||||||
GPatternSpec *pspec;
|
GPatternSpec *pspec;
|
||||||
gboolean seen_joker = FALSE, seen_wildcard = FALSE, more_wildcards = FALSE;
|
gboolean seen_joker = FALSE, seen_wildcard = FALSE, more_wildcards = FALSE;
|
||||||
gint hw_pos = -1, tw_pos = -1, hj_pos = -1, tj_pos = -1;
|
size_t hw_pos = 0, tw_pos = 0, hj_pos = 0, tj_pos = 0;
|
||||||
|
gboolean hw_pos_set = FALSE, hj_pos_set = FALSE;
|
||||||
gboolean follows_wildcard = FALSE;
|
gboolean follows_wildcard = FALSE;
|
||||||
guint pending_jokers = 0;
|
guint pending_jokers = 0;
|
||||||
const gchar *s;
|
const gchar *s;
|
||||||
gchar *d;
|
gchar *d;
|
||||||
guint i;
|
size_t i;
|
||||||
|
|
||||||
g_return_val_if_fail (pattern != NULL, NULL);
|
g_return_val_if_fail (pattern != NULL, NULL);
|
||||||
|
|
||||||
@@ -316,8 +317,11 @@ g_pattern_spec_new (const gchar *pattern)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
follows_wildcard = TRUE;
|
follows_wildcard = TRUE;
|
||||||
if (hw_pos < 0)
|
if (!hw_pos_set)
|
||||||
hw_pos = i;
|
{
|
||||||
|
hw_pos = i;
|
||||||
|
hw_pos_set = TRUE;
|
||||||
|
}
|
||||||
tw_pos = i;
|
tw_pos = i;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
@@ -328,8 +332,11 @@ g_pattern_spec_new (const gchar *pattern)
|
|||||||
default:
|
default:
|
||||||
for (; pending_jokers; pending_jokers--, i++) {
|
for (; pending_jokers; pending_jokers--, i++) {
|
||||||
*d++ = '?';
|
*d++ = '?';
|
||||||
if (hj_pos < 0)
|
if (!hj_pos_set)
|
||||||
hj_pos = i;
|
{
|
||||||
|
hj_pos = i;
|
||||||
|
hj_pos_set = TRUE;
|
||||||
|
}
|
||||||
tj_pos = i;
|
tj_pos = i;
|
||||||
}
|
}
|
||||||
follows_wildcard = FALSE;
|
follows_wildcard = FALSE;
|
||||||
@@ -342,13 +349,16 @@ g_pattern_spec_new (const gchar *pattern)
|
|||||||
}
|
}
|
||||||
for (; pending_jokers; pending_jokers--) {
|
for (; pending_jokers; pending_jokers--) {
|
||||||
*d++ = '?';
|
*d++ = '?';
|
||||||
if (hj_pos < 0)
|
if (!hj_pos_set)
|
||||||
hj_pos = i;
|
{
|
||||||
|
hj_pos = i;
|
||||||
|
hj_pos_set = TRUE;
|
||||||
|
}
|
||||||
tj_pos = i;
|
tj_pos = i;
|
||||||
}
|
}
|
||||||
*d++ = 0;
|
*d++ = 0;
|
||||||
seen_joker = hj_pos >= 0;
|
seen_joker = hj_pos_set;
|
||||||
seen_wildcard = hw_pos >= 0;
|
seen_wildcard = hw_pos_set;
|
||||||
more_wildcards = seen_wildcard && hw_pos != tw_pos;
|
more_wildcards = seen_wildcard && hw_pos != tw_pos;
|
||||||
if (seen_wildcard)
|
if (seen_wildcard)
|
||||||
pspec->max_length = G_MAXUINT;
|
pspec->max_length = G_MAXUINT;
|
||||||
|
@@ -185,7 +185,7 @@ g_rand_new (void)
|
|||||||
|
|
||||||
if (dev_urandom)
|
if (dev_urandom)
|
||||||
{
|
{
|
||||||
int r;
|
size_t r;
|
||||||
|
|
||||||
setvbuf (dev_urandom, NULL, _IONBF, 0);
|
setvbuf (dev_urandom, NULL, _IONBF, 0);
|
||||||
do
|
do
|
||||||
@@ -207,7 +207,7 @@ g_rand_new (void)
|
|||||||
if (!dev_urandom_exists)
|
if (!dev_urandom_exists)
|
||||||
{
|
{
|
||||||
gint64 now_us = g_get_real_time ();
|
gint64 now_us = g_get_real_time ();
|
||||||
seed[0] = now_us / G_USEC_PER_SEC;
|
seed[0] = (guint32) (now_us / G_USEC_PER_SEC);
|
||||||
seed[1] = now_us % G_USEC_PER_SEC;
|
seed[1] = now_us % G_USEC_PER_SEC;
|
||||||
seed[2] = getpid ();
|
seed[2] = getpid ();
|
||||||
seed[3] = getppid ();
|
seed[3] = getppid ();
|
||||||
|
@@ -1168,7 +1168,7 @@ g_scanner_peek_next_char (GScanner *scanner)
|
|||||||
}
|
}
|
||||||
else if (scanner->input_fd >= 0)
|
else if (scanner->input_fd >= 0)
|
||||||
{
|
{
|
||||||
gint count;
|
gssize count;
|
||||||
gchar *buffer;
|
gchar *buffer;
|
||||||
|
|
||||||
buffer = scanner->buffer;
|
buffer = scanner->buffer;
|
||||||
@@ -1218,7 +1218,7 @@ g_scanner_sync_file_offset (GScanner *scanner)
|
|||||||
|
|
||||||
if (scanner->input_fd >= 0 && scanner->text_end > scanner->text)
|
if (scanner->input_fd >= 0 && scanner->text_end > scanner->text)
|
||||||
{
|
{
|
||||||
gint buffered;
|
goffset buffered;
|
||||||
|
|
||||||
buffered = scanner->text_end - scanner->text;
|
buffered = scanner->text_end - scanner->text;
|
||||||
if (lseek (scanner->input_fd, - buffered, SEEK_CUR) >= 0)
|
if (lseek (scanner->input_fd, - buffered, SEEK_CUR) >= 0)
|
||||||
@@ -1243,7 +1243,7 @@ g_scanner_get_char (GScanner *scanner,
|
|||||||
fchar = *(scanner->text++);
|
fchar = *(scanner->text++);
|
||||||
else if (scanner->input_fd >= 0)
|
else if (scanner->input_fd >= 0)
|
||||||
{
|
{
|
||||||
gint count;
|
gssize count;
|
||||||
gchar *buffer;
|
gchar *buffer;
|
||||||
|
|
||||||
buffer = scanner->buffer;
|
buffer = scanner->buffer;
|
||||||
@@ -1694,12 +1694,12 @@ g_scanner_get_token_i (GScanner *scanner,
|
|||||||
* by copying between potentially-overlapping union members. */
|
* by copying between potentially-overlapping union members. */
|
||||||
if (scanner->config->store_int64)
|
if (scanner->config->store_int64)
|
||||||
{
|
{
|
||||||
gint64 temp = value_p->v_int64;
|
guint64 temp = value_p->v_int64;
|
||||||
value_p->v_float = temp;
|
value_p->v_float = temp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gint temp = value_p->v_int;
|
gulong temp = value_p->v_int;
|
||||||
value_p->v_float = temp;
|
value_p->v_float = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -56,6 +56,7 @@ static const struct {
|
|||||||
/* uppercase characters */
|
/* uppercase characters */
|
||||||
{ "EXAMPLE.COM", "example.com", FALSE, FALSE },
|
{ "EXAMPLE.COM", "example.com", FALSE, FALSE },
|
||||||
{ "\xc3\x89XAMPLE.COM", "xn--xample-9ua.com", TRUE, TRUE },
|
{ "\xc3\x89XAMPLE.COM", "xn--xample-9ua.com", TRUE, TRUE },
|
||||||
|
{ "Ⅷ.com", "viii.com", TRUE, FALSE },
|
||||||
|
|
||||||
/* unicode that decodes to ascii */
|
/* unicode that decodes to ascii */
|
||||||
{ "\xe2\x93\x94\xe2\x93\xa7\xe2\x93\x90\xe2\x93\x9c\xe2\x93\x9f\xe2\x93\x9b\xe2\x93\x94.com", "example.com", TRUE, FALSE },
|
{ "\xe2\x93\x94\xe2\x93\xa7\xe2\x93\x90\xe2\x93\x9c\xe2\x93\x9f\xe2\x93\x9b\xe2\x93\x94.com", "example.com", TRUE, FALSE },
|
||||||
|
@@ -613,6 +613,20 @@ test_default_handler (void)
|
|||||||
g_test_trap_assert_stdout ("*foo-DEBUG*baz*");
|
g_test_trap_assert_stdout ("*foo-DEBUG*baz*");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_journald_handler (void)
|
||||||
|
{
|
||||||
|
/* We can’t require that the journal exists on the test system. But if it
|
||||||
|
* does, we can check that the writer doesn’t crash. */
|
||||||
|
const GLogField fields[] = {
|
||||||
|
{ "MESSAGE", "This is a test message.", -1 },
|
||||||
|
{ "MESSAGE_ID", "7187d27ad7f84351b76b7612eef52cd6", -1 },
|
||||||
|
{ "MY_APPLICATION_CUSTOM_FIELD", "some debug string", -1 },
|
||||||
|
};
|
||||||
|
|
||||||
|
g_log_writer_journald (G_LOG_LEVEL_DEBUG, fields, G_N_ELEMENTS (fields), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_fatal_log_mask (void)
|
test_fatal_log_mask (void)
|
||||||
{
|
{
|
||||||
@@ -1151,6 +1165,7 @@ main (int argc, char *argv[])
|
|||||||
g_test_add_func ("/logging/default-handler/subprocess/would-drop-env-systemd", test_default_handler_would_drop_env_systemd);
|
g_test_add_func ("/logging/default-handler/subprocess/would-drop-env-systemd", test_default_handler_would_drop_env_systemd);
|
||||||
g_test_add_func ("/logging/default-handler/subprocess/would-drop-robustness", test_default_handler_would_drop_robustness);
|
g_test_add_func ("/logging/default-handler/subprocess/would-drop-robustness", test_default_handler_would_drop_robustness);
|
||||||
g_test_add_func ("/logging/default-handler/subprocess/structured-logging-non-null-terminated-strings", test_default_handler_structured_logging_non_nul_terminated_strings);
|
g_test_add_func ("/logging/default-handler/subprocess/structured-logging-non-null-terminated-strings", test_default_handler_structured_logging_non_nul_terminated_strings);
|
||||||
|
g_test_add_func ("/logging/journald-handler", test_journald_handler);
|
||||||
g_test_add_func ("/logging/warnings", test_warnings);
|
g_test_add_func ("/logging/warnings", test_warnings);
|
||||||
g_test_add_func ("/logging/fatal-log-mask", test_fatal_log_mask);
|
g_test_add_func ("/logging/fatal-log-mask", test_fatal_log_mask);
|
||||||
g_test_add_func ("/logging/set-handler", test_set_handler);
|
g_test_add_func ("/logging/set-handler", test_set_handler);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -18,10 +18,15 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <glib/gstdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef G_OS_WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* GScanner fixture */
|
/* GScanner fixture */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -129,6 +134,169 @@ test_scanner_tokens (ScannerFixture *fix,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_scanner_multiline_comment (void)
|
||||||
|
{
|
||||||
|
GScanner *scanner = NULL;
|
||||||
|
const char buf[] = "/** this\n * is\n * multilined */";
|
||||||
|
const size_t buflen = strlen (buf);
|
||||||
|
|
||||||
|
scanner = g_scanner_new (NULL);
|
||||||
|
scanner->config->skip_comment_multi = FALSE;
|
||||||
|
|
||||||
|
g_scanner_input_text (scanner, buf, buflen);
|
||||||
|
|
||||||
|
g_assert_cmpint (g_scanner_cur_token (scanner), ==, G_TOKEN_NONE);
|
||||||
|
g_scanner_get_next_token (scanner);
|
||||||
|
g_assert_cmpint (g_scanner_cur_token (scanner), ==, G_TOKEN_COMMENT_MULTI);
|
||||||
|
g_assert_cmpint (g_scanner_cur_line (scanner), ==, 3);
|
||||||
|
g_assert_cmpstr (g_scanner_cur_value (scanner).v_comment, ==, "* this\n * is\n * multilined ");
|
||||||
|
g_assert_cmpint (g_scanner_get_next_token (scanner), ==, G_TOKEN_EOF);
|
||||||
|
|
||||||
|
g_scanner_destroy (scanner);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_scanner_int_to_float (void)
|
||||||
|
{
|
||||||
|
GScanner *scanner = NULL;
|
||||||
|
const char buf[] = "4294967295";
|
||||||
|
const size_t buflen = strlen (buf);
|
||||||
|
|
||||||
|
scanner = g_scanner_new (NULL);
|
||||||
|
scanner->config->int_2_float = TRUE;
|
||||||
|
|
||||||
|
g_scanner_input_text (scanner, buf, buflen);
|
||||||
|
|
||||||
|
g_assert_cmpint (g_scanner_cur_token (scanner), ==, G_TOKEN_NONE);
|
||||||
|
g_scanner_get_next_token (scanner);
|
||||||
|
g_assert_cmpint (g_scanner_cur_token (scanner), ==, G_TOKEN_FLOAT);
|
||||||
|
g_assert_cmpint (g_scanner_cur_line (scanner), ==, 1);
|
||||||
|
g_assert_cmpfloat (g_scanner_cur_value (scanner).v_float, ==, 4294967295.0);
|
||||||
|
g_assert_cmpint (g_scanner_get_next_token (scanner), ==, G_TOKEN_EOF);
|
||||||
|
|
||||||
|
g_scanner_destroy (scanner);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_scanner_fd_input (void)
|
||||||
|
{
|
||||||
|
/* GScanner does some internal buffering when reading from an FD, reading in
|
||||||
|
* chunks of `READ_BUFFER_SIZE` (currently 4000B) to an internal buffer. The
|
||||||
|
* parsing codepaths differ significantly depending on whether there’s data in
|
||||||
|
* the buffer, so all parsing operations have to be tested with chunk
|
||||||
|
* boundaries on each of the characters in that operation.
|
||||||
|
*
|
||||||
|
* Do that by prefixing the buffer we’re testing with a variable amount of
|
||||||
|
* whitespace. Whitespace is (by default) ignored by the scanner, so won’t
|
||||||
|
* affect the test other than by letting us choose where in the test string
|
||||||
|
* the chunk boundaries fall. */
|
||||||
|
const size_t whitespace_lens[] = { 0, 3998, 3999, 4000, 4001 };
|
||||||
|
|
||||||
|
for (size_t i = 0; i < G_N_ELEMENTS (whitespace_lens); i++)
|
||||||
|
{
|
||||||
|
GScanner *scanner = NULL;
|
||||||
|
char *filename = NULL;
|
||||||
|
int fd = -1;
|
||||||
|
char *buf = NULL;
|
||||||
|
const size_t whitespace_len = whitespace_lens[i];
|
||||||
|
size_t buflen;
|
||||||
|
const char *buf_suffix = "/** this\n * is\n * multilined */";
|
||||||
|
|
||||||
|
buflen = whitespace_len + strlen (buf_suffix) + 1;
|
||||||
|
buf = g_malloc (buflen);
|
||||||
|
memset (buf, ' ', whitespace_len);
|
||||||
|
memcpy (buf + whitespace_len, buf_suffix, strlen (buf_suffix));
|
||||||
|
buf[buflen - 1] = '\0';
|
||||||
|
|
||||||
|
scanner = g_scanner_new (NULL);
|
||||||
|
scanner->config->skip_comment_multi = FALSE;
|
||||||
|
|
||||||
|
filename = g_strdup ("scanner-fd-input-XXXXXX");
|
||||||
|
fd = g_mkstemp (filename);
|
||||||
|
g_assert_cmpint (fd, >=, 0);
|
||||||
|
|
||||||
|
g_assert_cmpint (write (fd, buf, buflen), ==, buflen);
|
||||||
|
g_assert_no_errno (lseek (fd, 0, SEEK_SET));
|
||||||
|
|
||||||
|
g_scanner_input_file (scanner, fd);
|
||||||
|
|
||||||
|
g_assert_cmpint (g_scanner_cur_token (scanner), ==, G_TOKEN_NONE);
|
||||||
|
g_scanner_get_next_token (scanner);
|
||||||
|
g_assert_cmpint (g_scanner_cur_token (scanner), ==, G_TOKEN_COMMENT_MULTI);
|
||||||
|
g_assert_cmpint (g_scanner_cur_line (scanner), ==, 3);
|
||||||
|
g_assert_cmpstr (g_scanner_cur_value (scanner).v_comment, ==, "* this\n * is\n * multilined ");
|
||||||
|
g_assert_cmpint (g_scanner_get_next_token (scanner), ==, G_TOKEN_EOF);
|
||||||
|
|
||||||
|
g_close (fd, NULL);
|
||||||
|
g_free (filename);
|
||||||
|
g_free (buf);
|
||||||
|
g_scanner_destroy (scanner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_scanner_fd_input_rewind (void)
|
||||||
|
{
|
||||||
|
/* GScanner does some internal buffering when reading from an FD, reading in
|
||||||
|
* chunks of `READ_BUFFER_SIZE` (currently 4000B) to an internal buffer. It
|
||||||
|
* allows the input FD’s file offset to be positioned to match the current
|
||||||
|
* parsing position. Test that works. */
|
||||||
|
GScanner *scanner = NULL;
|
||||||
|
char *filename = NULL;
|
||||||
|
int fd = -1;
|
||||||
|
char *buf = NULL;
|
||||||
|
const size_t whitespace_len = 4000;
|
||||||
|
size_t buflen;
|
||||||
|
const char *buf_suffix = "({})";
|
||||||
|
const struct
|
||||||
|
{
|
||||||
|
GTokenType expected_token;
|
||||||
|
off_t expected_offset; /* offset after consuming @expected_token */
|
||||||
|
}
|
||||||
|
tokens_and_offsets[] =
|
||||||
|
{
|
||||||
|
{ G_TOKEN_LEFT_PAREN, whitespace_len + 1 },
|
||||||
|
{ G_TOKEN_LEFT_CURLY, whitespace_len + 2 },
|
||||||
|
{ G_TOKEN_RIGHT_CURLY, whitespace_len + 3 },
|
||||||
|
{ G_TOKEN_RIGHT_PAREN, whitespace_len + 4 },
|
||||||
|
};
|
||||||
|
|
||||||
|
buflen = whitespace_len + strlen (buf_suffix) + 1;
|
||||||
|
buf = g_malloc (buflen);
|
||||||
|
memset (buf, ' ', whitespace_len);
|
||||||
|
memcpy (buf + whitespace_len, buf_suffix, strlen (buf_suffix));
|
||||||
|
buf[buflen - 1] = '\0';
|
||||||
|
|
||||||
|
scanner = g_scanner_new (NULL);
|
||||||
|
|
||||||
|
filename = g_strdup ("scanner-fd-input-XXXXXX");
|
||||||
|
fd = g_mkstemp (filename);
|
||||||
|
g_assert_cmpint (fd, >=, 0);
|
||||||
|
|
||||||
|
g_assert_cmpint (write (fd, buf, buflen), ==, buflen);
|
||||||
|
g_assert_no_errno (lseek (fd, 0, SEEK_SET));
|
||||||
|
|
||||||
|
g_scanner_input_file (scanner, fd);
|
||||||
|
|
||||||
|
g_assert_cmpint (g_scanner_cur_token (scanner), ==, G_TOKEN_NONE);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < G_N_ELEMENTS (tokens_and_offsets); i++)
|
||||||
|
{
|
||||||
|
g_scanner_get_next_token (scanner);
|
||||||
|
g_scanner_sync_file_offset (scanner);
|
||||||
|
g_assert_cmpint (g_scanner_cur_token (scanner), ==, tokens_and_offsets[i].expected_token);
|
||||||
|
g_assert_cmpint (lseek (fd, 0, SEEK_CUR), ==, tokens_and_offsets[i].expected_offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_assert_cmpint (g_scanner_get_next_token (scanner), ==, G_TOKEN_EOF);
|
||||||
|
|
||||||
|
g_close (fd, NULL);
|
||||||
|
g_free (filename);
|
||||||
|
g_free (buf);
|
||||||
|
g_scanner_destroy (scanner);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
@@ -139,6 +307,10 @@ main (int argc,
|
|||||||
g_test_add ("/scanner/error", ScannerFixture, 0, scanner_fixture_setup, test_scanner_error, scanner_fixture_teardown);
|
g_test_add ("/scanner/error", ScannerFixture, 0, scanner_fixture_setup, test_scanner_error, scanner_fixture_teardown);
|
||||||
g_test_add ("/scanner/symbols", ScannerFixture, 0, scanner_fixture_setup, test_scanner_symbols, scanner_fixture_teardown);
|
g_test_add ("/scanner/symbols", ScannerFixture, 0, scanner_fixture_setup, test_scanner_symbols, scanner_fixture_teardown);
|
||||||
g_test_add ("/scanner/tokens", ScannerFixture, 0, scanner_fixture_setup, test_scanner_tokens, scanner_fixture_teardown);
|
g_test_add ("/scanner/tokens", ScannerFixture, 0, scanner_fixture_setup, test_scanner_tokens, scanner_fixture_teardown);
|
||||||
|
g_test_add_func ("/scanner/multiline-comment", test_scanner_multiline_comment);
|
||||||
|
g_test_add_func ("/scanner/int-to-float", test_scanner_int_to_float);
|
||||||
|
g_test_add_func ("/scanner/fd-input", test_scanner_fd_input);
|
||||||
|
g_test_add_func ("/scanner/fd-input/rewind", test_scanner_fd_input_rewind);
|
||||||
|
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user