mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-05-10 07:53:12 +02:00
Merge branch 'wsign-conversion' into 'main'
Various -Wsign-conversion warning fixes See merge request GNOME/glib!4590
This commit is contained in:
commit
2d66caf6cb
45
fuzzing/fuzz_get_locale_variants.c
Normal file
45
fuzzing/fuzz_get_locale_variants.c
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2025 GNOME Foundation, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* Authors:
|
||||
* - Philip Withnall <pwithnall@gnome.org>
|
||||
*/
|
||||
|
||||
#include "fuzz.h"
|
||||
|
||||
int
|
||||
LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
|
||||
{
|
||||
unsigned char *nul_terminated_data = NULL;
|
||||
char **v;
|
||||
|
||||
fuzz_set_logging_func ();
|
||||
|
||||
/* ignore @size (g_get_locale_variants() doesn’t support it); ensure @data is nul-terminated */
|
||||
nul_terminated_data = (unsigned char *) g_strndup ((const char *) data, size);
|
||||
|
||||
v = g_get_locale_variants ((char *) nul_terminated_data);
|
||||
g_assert_nonnull (v);
|
||||
/* g_get_locale_variants() guarantees that the input is always in the output: */
|
||||
g_assert_true (g_strv_contains ((const char * const *) v, (char *) nul_terminated_data));
|
||||
g_strfreev (v);
|
||||
|
||||
g_free (nul_terminated_data);
|
||||
|
||||
return 0;
|
||||
}
|
@ -25,6 +25,7 @@ fuzz_targets = [
|
||||
'fuzz_date_parse',
|
||||
'fuzz_date_time_new_from_iso8601',
|
||||
'fuzz_dbus_message',
|
||||
'fuzz_get_locale_variants',
|
||||
'fuzz_inet_address_mask_new_from_string',
|
||||
'fuzz_inet_address_new_from_string',
|
||||
'fuzz_inet_socket_address_new_from_string',
|
||||
|
@ -9,11 +9,20 @@ xdgmime_sources = files(
|
||||
'xdgmimeparent.c',
|
||||
)
|
||||
|
||||
# glib enables various warnings which the xdgmime code wasn’t designed to
|
||||
# work with
|
||||
extra_xdgmime_args = cc.get_supported_arguments([
|
||||
'-Wno-sign-conversion',
|
||||
])
|
||||
|
||||
xdgmime_lib = static_library('xdgmime',
|
||||
sources : xdgmime_sources,
|
||||
include_directories : [configinc],
|
||||
pic : true,
|
||||
c_args : [ '-DHAVE_CONFIG_H',
|
||||
'-DXDG_PREFIX=_gio_xdg' ],
|
||||
c_args : [
|
||||
'-DHAVE_CONFIG_H',
|
||||
'-DXDG_PREFIX=_gio_xdg',
|
||||
extra_xdgmime_args,
|
||||
],
|
||||
gnu_symbol_visibility : 'hidden',
|
||||
)
|
||||
|
@ -40,7 +40,7 @@ g_mem_chunk_new (const gchar *name,
|
||||
g_return_val_if_fail (atom_size > 0, NULL);
|
||||
|
||||
mem_chunk = g_slice_new (GMemChunk);
|
||||
mem_chunk->alloc_size = atom_size;
|
||||
mem_chunk->alloc_size = (guint) atom_size;
|
||||
|
||||
return mem_chunk;
|
||||
}
|
||||
|
@ -97,15 +97,19 @@ typedef struct _GRealTuples GRealTuples;
|
||||
|
||||
struct _GRelation
|
||||
{
|
||||
gint fields;
|
||||
gint current_field;
|
||||
size_t fields;
|
||||
size_t current_field;
|
||||
|
||||
GHashTable *all_tuples;
|
||||
GHashTable **hashed_tuple_tables;
|
||||
|
||||
gint count;
|
||||
size_t count;
|
||||
};
|
||||
|
||||
static size_t relation_count_internal (GRelation *relation,
|
||||
gconstpointer key,
|
||||
size_t field);
|
||||
|
||||
/**
|
||||
* GTuples:
|
||||
* @len: the number of records that matched.
|
||||
@ -119,8 +123,8 @@ struct _GRelation
|
||||
**/
|
||||
struct _GRealTuples
|
||||
{
|
||||
gint len;
|
||||
gint width;
|
||||
guint len;
|
||||
size_t width;
|
||||
gpointer *data;
|
||||
};
|
||||
|
||||
@ -195,10 +199,15 @@ GRelation*
|
||||
g_relation_new (gint fields)
|
||||
{
|
||||
GRelation* rel = g_new0 (GRelation, 1);
|
||||
size_t unsigned_fields;
|
||||
|
||||
rel->fields = fields;
|
||||
rel->all_tuples = g_hash_table_new (tuple_hash (fields), tuple_equal (fields));
|
||||
rel->hashed_tuple_tables = g_new0 (GHashTable*, fields);
|
||||
g_return_val_if_fail (fields == 2, NULL);
|
||||
|
||||
unsigned_fields = (size_t) fields;
|
||||
|
||||
rel->fields = unsigned_fields;
|
||||
rel->all_tuples = g_hash_table_new (tuple_hash (unsigned_fields), tuple_equal (unsigned_fields));
|
||||
rel->hashed_tuple_tables = g_new0 (GHashTable*, unsigned_fields);
|
||||
|
||||
return rel;
|
||||
}
|
||||
@ -232,11 +241,9 @@ g_relation_free_array (gpointer key, gpointer value, gpointer user_data)
|
||||
void
|
||||
g_relation_destroy (GRelation *relation)
|
||||
{
|
||||
gint i;
|
||||
|
||||
if (relation)
|
||||
{
|
||||
for (i = 0; i < relation->fields; i += 1)
|
||||
for (size_t i = 0; i < relation->fields; i += 1)
|
||||
{
|
||||
if (relation->hashed_tuple_tables[i])
|
||||
{
|
||||
@ -295,11 +302,10 @@ g_relation_insert (GRelation *relation,
|
||||
{
|
||||
gpointer* tuple = g_slice_alloc (relation->fields * sizeof (gpointer));
|
||||
va_list args;
|
||||
gint i;
|
||||
|
||||
va_start (args, relation);
|
||||
|
||||
for (i = 0; i < relation->fields; i += 1)
|
||||
for (size_t i = 0; i < relation->fields; i += 1)
|
||||
tuple[i] = va_arg (args, gpointer);
|
||||
|
||||
va_end (args);
|
||||
@ -308,7 +314,7 @@ g_relation_insert (GRelation *relation,
|
||||
|
||||
relation->count += 1;
|
||||
|
||||
for (i = 0; i < relation->fields; i += 1)
|
||||
for (size_t i = 0; i < relation->fields; i += 1)
|
||||
{
|
||||
GHashTable *table;
|
||||
gpointer key;
|
||||
@ -339,11 +345,10 @@ g_relation_delete_tuple (gpointer tuple_key,
|
||||
{
|
||||
gpointer *tuple = (gpointer*) tuple_value;
|
||||
GRelation *relation = (GRelation *) user_data;
|
||||
gint j;
|
||||
|
||||
g_assert (tuple_key == tuple_value);
|
||||
|
||||
for (j = 0; j < relation->fields; j += 1)
|
||||
for (size_t j = 0; j < relation->fields; j += 1)
|
||||
{
|
||||
GHashTable *one_table = relation->hashed_tuple_tables[j];
|
||||
gpointer one_key;
|
||||
@ -389,11 +394,14 @@ g_relation_delete (GRelation *relation,
|
||||
{
|
||||
GHashTable *table;
|
||||
GHashTable *key_table;
|
||||
gint count;
|
||||
size_t count;
|
||||
size_t unsigned_field;
|
||||
|
||||
g_return_val_if_fail (relation != NULL, 0);
|
||||
g_return_val_if_fail (field >= 0 && (size_t) field < relation->fields, 0);
|
||||
|
||||
table = relation->hashed_tuple_tables[field];
|
||||
unsigned_field = (size_t) field;
|
||||
table = relation->hashed_tuple_tables[unsigned_field];
|
||||
count = relation->count;
|
||||
|
||||
g_return_val_if_fail (table != NULL, 0);
|
||||
@ -403,7 +411,7 @@ g_relation_delete (GRelation *relation,
|
||||
if (!key_table)
|
||||
return 0;
|
||||
|
||||
relation->current_field = field;
|
||||
relation->current_field = unsigned_field;
|
||||
|
||||
g_hash_table_foreach (key_table, g_relation_delete_tuple, relation);
|
||||
|
||||
@ -423,7 +431,7 @@ g_relation_select_tuple (gpointer tuple_key,
|
||||
{
|
||||
gpointer *tuple = (gpointer*) tuple_value;
|
||||
GRealTuples *tuples = (GRealTuples*) user_data;
|
||||
gint stride = sizeof (gpointer) * tuples->width;
|
||||
size_t stride = sizeof (gpointer) * tuples->width;
|
||||
|
||||
g_assert (tuple_key == tuple_value);
|
||||
|
||||
@ -456,11 +464,14 @@ g_relation_select (GRelation *relation,
|
||||
GHashTable *table;
|
||||
GHashTable *key_table;
|
||||
GRealTuples *tuples;
|
||||
gint count;
|
||||
size_t count;
|
||||
size_t unsigned_field;
|
||||
|
||||
g_return_val_if_fail (relation != NULL, NULL);
|
||||
g_return_val_if_fail (field >= 0 && (size_t) field < relation->fields, NULL);
|
||||
|
||||
table = relation->hashed_tuple_tables[field];
|
||||
unsigned_field = (size_t) field;
|
||||
table = relation->hashed_tuple_tables[unsigned_field];
|
||||
|
||||
g_return_val_if_fail (table != NULL, NULL);
|
||||
|
||||
@ -470,18 +481,41 @@ g_relation_select (GRelation *relation,
|
||||
if (!key_table)
|
||||
return (GTuples*)tuples;
|
||||
|
||||
count = g_relation_count (relation, key, field);
|
||||
count = relation_count_internal (relation, key, unsigned_field);
|
||||
|
||||
tuples->data = g_malloc (sizeof (gpointer) * relation->fields * count);
|
||||
tuples->width = relation->fields;
|
||||
|
||||
g_hash_table_foreach (key_table, g_relation_select_tuple, tuples);
|
||||
|
||||
g_assert (count == tuples->len);
|
||||
g_assert (count == (size_t) tuples->len);
|
||||
|
||||
return (GTuples*)tuples;
|
||||
}
|
||||
|
||||
static size_t
|
||||
relation_count_internal (GRelation *relation,
|
||||
gconstpointer key,
|
||||
size_t field)
|
||||
{
|
||||
GHashTable *table;
|
||||
GHashTable *key_table;
|
||||
|
||||
g_return_val_if_fail (relation != NULL, 0);
|
||||
g_return_val_if_fail (field < relation->fields, 0);
|
||||
|
||||
table = relation->hashed_tuple_tables[field];
|
||||
|
||||
g_return_val_if_fail (table != NULL, 0);
|
||||
|
||||
key_table = g_hash_table_lookup (table, key);
|
||||
|
||||
if (!key_table)
|
||||
return 0;
|
||||
|
||||
return g_hash_table_size (key_table);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_relation_count:
|
||||
* @relation: a #GRelation.
|
||||
@ -500,21 +534,14 @@ g_relation_count (GRelation *relation,
|
||||
gconstpointer key,
|
||||
gint field)
|
||||
{
|
||||
GHashTable *table;
|
||||
GHashTable *key_table;
|
||||
|
||||
g_return_val_if_fail (relation != NULL, 0);
|
||||
unsigned int n_matches;
|
||||
|
||||
table = relation->hashed_tuple_tables[field];
|
||||
g_return_val_if_fail (field >= 0 && (size_t) field < relation->fields, 0);
|
||||
|
||||
g_return_val_if_fail (table != NULL, 0);
|
||||
|
||||
key_table = g_hash_table_lookup (table, key);
|
||||
|
||||
if (!key_table)
|
||||
return 0;
|
||||
|
||||
return g_hash_table_size (key_table);
|
||||
/* Do the best we can with the limited return type */
|
||||
n_matches = relation_count_internal (relation, key, (size_t) field);
|
||||
g_return_val_if_fail (n_matches <= G_MAXINT, G_MAXINT);
|
||||
return (gint) n_matches;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -536,12 +563,11 @@ g_relation_exists (GRelation *relation, ...)
|
||||
{
|
||||
gpointer *tuple = g_slice_alloc (relation->fields * sizeof (gpointer));
|
||||
va_list args;
|
||||
gint i;
|
||||
gboolean result;
|
||||
|
||||
va_start(args, relation);
|
||||
|
||||
for (i = 0; i < relation->fields; i += 1)
|
||||
for (size_t i = 0; i < relation->fields; i += 1)
|
||||
tuple[i] = va_arg(args, gpointer);
|
||||
|
||||
va_end(args);
|
||||
@ -596,11 +622,16 @@ g_tuples_index (GTuples *tuples0,
|
||||
gint field)
|
||||
{
|
||||
GRealTuples *tuples = (GRealTuples*) tuples0;
|
||||
|
||||
size_t unsigned_index, unsigned_field;
|
||||
|
||||
g_return_val_if_fail (tuples0 != NULL, NULL);
|
||||
g_return_val_if_fail (field < tuples->width, NULL);
|
||||
|
||||
return tuples->data[index * tuples->width + field];
|
||||
g_return_val_if_fail (index >= 0, NULL);
|
||||
g_return_val_if_fail (field >= 0 && (size_t) field < tuples->width, NULL);
|
||||
|
||||
unsigned_index = (size_t) index;
|
||||
unsigned_field = (size_t) field;
|
||||
|
||||
return tuples->data[unsigned_index * tuples->width + unsigned_field];
|
||||
}
|
||||
|
||||
/* Print
|
||||
@ -611,14 +642,13 @@ g_relation_print_one (gpointer tuple_key,
|
||||
gpointer tuple_value,
|
||||
gpointer user_data)
|
||||
{
|
||||
gint i;
|
||||
GString *gstring;
|
||||
GRelation* rel = (GRelation*) user_data;
|
||||
gpointer* tuples = (gpointer*) tuple_value;
|
||||
|
||||
gstring = g_string_new ("[");
|
||||
|
||||
for (i = 0; i < rel->fields; i += 1)
|
||||
for (size_t i = 0; i < rel->fields; i += 1)
|
||||
{
|
||||
g_string_append_printf (gstring, "%p", tuples[i]);
|
||||
|
||||
@ -658,20 +688,18 @@ g_relation_print_index (gpointer tuple_key,
|
||||
void
|
||||
g_relation_print (GRelation *relation)
|
||||
{
|
||||
gint i;
|
||||
|
||||
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "*** all tuples (%d)", relation->count);
|
||||
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "*** all tuples (%" G_GSIZE_FORMAT ")", relation->count);
|
||||
|
||||
g_hash_table_foreach (relation->all_tuples,
|
||||
g_relation_print_one,
|
||||
relation);
|
||||
|
||||
for (i = 0; i < relation->fields; i += 1)
|
||||
for (size_t i = 0; i < relation->fields; i += 1)
|
||||
{
|
||||
if (relation->hashed_tuple_tables[i] == NULL)
|
||||
continue;
|
||||
|
||||
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "*** index %d", i);
|
||||
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "*** index %" G_GSIZE_FORMAT, i);
|
||||
|
||||
g_hash_table_foreach (relation->hashed_tuple_tables[i],
|
||||
g_relation_print_index,
|
||||
|
@ -135,7 +135,7 @@ GThreadFunctions g_thread_functions_for_glib_use =
|
||||
static guint64
|
||||
gettime (void)
|
||||
{
|
||||
return g_get_monotonic_time () * 1000;
|
||||
return (guint64) g_get_monotonic_time () * 1000;
|
||||
}
|
||||
|
||||
guint64 (*g_thread_gettime) (void) = gettime;
|
||||
@ -803,8 +803,8 @@ guint
|
||||
g_static_rec_mutex_unlock_full (GStaticRecMutex *mutex)
|
||||
{
|
||||
GRecMutex *rm;
|
||||
gint depth;
|
||||
gint i;
|
||||
guint depth;
|
||||
guint i;
|
||||
|
||||
rm = g_static_rec_mutex_get_rec_mutex_impl (mutex);
|
||||
|
||||
|
@ -70,7 +70,7 @@ get_alias_hash (void)
|
||||
const char *canonical;
|
||||
const char *alias;
|
||||
const char **alias_array;
|
||||
int count = 0;
|
||||
size_t count = 0;
|
||||
|
||||
alias = aliases;
|
||||
aliases += strlen (aliases) + 1;
|
||||
@ -537,6 +537,7 @@ enum
|
||||
};
|
||||
|
||||
/* Break an X/Open style locale specification into components
|
||||
* e.g. `en_GB` or `uz_UZ.utf8@cyrillic`
|
||||
*/
|
||||
static guint
|
||||
explode_locale (const gchar *locale,
|
||||
@ -563,7 +564,7 @@ explode_locale (const gchar *locale,
|
||||
else
|
||||
at_pos = locale + strlen (locale);
|
||||
|
||||
if (dot_pos)
|
||||
if (dot_pos && dot_pos < at_pos)
|
||||
{
|
||||
mask |= COMPONENT_CODESET;
|
||||
*codeset = g_strndup (dot_pos, at_pos - dot_pos);
|
||||
@ -571,7 +572,7 @@ explode_locale (const gchar *locale,
|
||||
else
|
||||
dot_pos = at_pos;
|
||||
|
||||
if (uscore_pos)
|
||||
if (uscore_pos && uscore_pos < dot_pos)
|
||||
{
|
||||
mask |= COMPONENT_TERRITORY;
|
||||
*territory = g_strndup (uscore_pos, dot_pos - uscore_pos);
|
||||
@ -579,6 +580,7 @@ explode_locale (const gchar *locale,
|
||||
else
|
||||
uscore_pos = dot_pos;
|
||||
|
||||
g_assert (uscore_pos >= locale);
|
||||
*language = g_strndup (locale, uscore_pos - locale);
|
||||
|
||||
return mask;
|
||||
|
@ -165,7 +165,7 @@ md5_byte_reverse (guchar *buffer,
|
||||
#else
|
||||
static inline void
|
||||
sha_byte_reverse (guint32 *buffer,
|
||||
gint length)
|
||||
size_t length)
|
||||
{
|
||||
length /= sizeof (guint32);
|
||||
while (length--)
|
||||
@ -749,11 +749,11 @@ sha1_sum_update (Sha1sum *sha1,
|
||||
static void
|
||||
sha1_sum_close (Sha1sum *sha1)
|
||||
{
|
||||
gint count;
|
||||
size_t count;
|
||||
guchar *data_p;
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
count = (gint) ((sha1->bits[0] >> 3) & 0x3f);
|
||||
count = (sha1->bits[0] >> 3) & 0x3f;
|
||||
|
||||
/* Set the first char of padding to 0x80. This is safe since there is
|
||||
always at least one byte free */
|
||||
@ -806,7 +806,7 @@ static void
|
||||
sha1_sum_digest (Sha1sum *sha1,
|
||||
guint8 *digest)
|
||||
{
|
||||
gint i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < SHA1_DIGEST_LEN; i++)
|
||||
digest[i] = sha1->digest[i];
|
||||
@ -1328,17 +1328,18 @@ static void
|
||||
sha512_sum_close (Sha512sum *sha512)
|
||||
{
|
||||
guint l;
|
||||
gint zeros;
|
||||
size_t zeros;
|
||||
guint8 pad[SHA2_BLOCK_LEN * 2] = { 0, };
|
||||
guint pad_len = 0;
|
||||
gint i;
|
||||
size_t pad_len = 0;
|
||||
size_t i;
|
||||
|
||||
/* apply padding [§5.1.2] */
|
||||
l = sha512->block_len * 8;
|
||||
zeros = 896 - (l + 1);
|
||||
|
||||
if (zeros < 0)
|
||||
zeros += 128 * 8;
|
||||
if (896 < l + 1)
|
||||
zeros = 896 - (l + 1) + 128 * 8;
|
||||
else
|
||||
zeros = 896 - (l + 1);
|
||||
|
||||
pad[0] = 0x80; /* 1000 0000 */
|
||||
zeros -= 7;
|
||||
@ -1571,33 +1572,20 @@ g_checksum_free (GChecksum *checksum)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* g_checksum_update:
|
||||
* @checksum: a #GChecksum
|
||||
* @data: (array length=length) (element-type guint8): buffer used to compute the checksum
|
||||
* @length: size of the buffer, or -1 if it is a null-terminated string.
|
||||
*
|
||||
* Feeds @data into an existing #GChecksum. The checksum must still be
|
||||
* open, that is g_checksum_get_string() or g_checksum_get_digest() must
|
||||
* not have been called on @checksum.
|
||||
*
|
||||
* Since: 2.16
|
||||
*/
|
||||
void
|
||||
g_checksum_update (GChecksum *checksum,
|
||||
const guchar *data,
|
||||
gssize length)
|
||||
/* Internal variant of g_checksum_update() which takes an explicit length and
|
||||
* doesn’t use strlen() internally. */
|
||||
static void
|
||||
checksum_update_internal (GChecksum *checksum,
|
||||
const guchar *data,
|
||||
size_t length)
|
||||
{
|
||||
g_return_if_fail (checksum != NULL);
|
||||
g_return_if_fail (length == 0 || data != NULL);
|
||||
|
||||
if (length < 0)
|
||||
length = strlen ((const gchar *) data);
|
||||
|
||||
if (checksum->digest_str)
|
||||
{
|
||||
g_warning ("The checksum '%s' has been closed and cannot be updated "
|
||||
"anymore.",
|
||||
"any more.",
|
||||
checksum->digest_str);
|
||||
return;
|
||||
}
|
||||
@ -1623,6 +1611,36 @@ g_checksum_update (GChecksum *checksum,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* g_checksum_update:
|
||||
* @checksum: a #GChecksum
|
||||
* @data: (array length=length) (element-type guint8): buffer used to compute the checksum
|
||||
* @length: size of the buffer, or -1 if it is a null-terminated string.
|
||||
*
|
||||
* Feeds @data into an existing #GChecksum. The checksum must still be
|
||||
* open, that is g_checksum_get_string() or g_checksum_get_digest() must
|
||||
* not have been called on @checksum.
|
||||
*
|
||||
* Since: 2.16
|
||||
*/
|
||||
void
|
||||
g_checksum_update (GChecksum *checksum,
|
||||
const guchar *data,
|
||||
gssize length)
|
||||
{
|
||||
size_t unsigned_length;
|
||||
|
||||
g_return_if_fail (checksum != NULL);
|
||||
g_return_if_fail (length == 0 || data != NULL);
|
||||
|
||||
if (length < 0)
|
||||
unsigned_length = strlen ((const gchar *) data);
|
||||
else
|
||||
unsigned_length = (size_t) length;
|
||||
|
||||
checksum_update_internal (checksum, data, unsigned_length);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_checksum_get_string:
|
||||
* @checksum: a #GChecksum
|
||||
@ -1704,11 +1722,14 @@ g_checksum_get_digest (GChecksum *checksum,
|
||||
{
|
||||
gboolean checksum_open = FALSE;
|
||||
gchar *str = NULL;
|
||||
gssize signed_len;
|
||||
gsize len;
|
||||
|
||||
g_return_if_fail (checksum != NULL);
|
||||
|
||||
len = g_checksum_type_get_length (checksum->type);
|
||||
signed_len = g_checksum_type_get_length (checksum->type);
|
||||
g_assert (signed_len >= 0); /* @checksum should be internally consistent */
|
||||
len = (size_t) signed_len;
|
||||
g_return_if_fail (*digest_len >= len);
|
||||
|
||||
checksum_open = !!(checksum->digest_str == NULL);
|
||||
@ -1799,7 +1820,7 @@ g_compute_checksum_for_data (GChecksumType checksum_type,
|
||||
if (!checksum)
|
||||
return NULL;
|
||||
|
||||
g_checksum_update (checksum, data, length);
|
||||
checksum_update_internal (checksum, data, length);
|
||||
retval = g_strdup (g_checksum_get_string (checksum));
|
||||
g_checksum_free (checksum);
|
||||
|
||||
@ -1827,12 +1848,16 @@ g_compute_checksum_for_string (GChecksumType checksum_type,
|
||||
const gchar *str,
|
||||
gssize length)
|
||||
{
|
||||
size_t unsigned_length;
|
||||
|
||||
g_return_val_if_fail (length == 0 || str != NULL, NULL);
|
||||
|
||||
if (length < 0)
|
||||
length = strlen (str);
|
||||
unsigned_length = strlen (str);
|
||||
else
|
||||
unsigned_length = (size_t) length;
|
||||
|
||||
return g_compute_checksum_for_data (checksum_type, (const guchar *) str, length);
|
||||
return g_compute_checksum_for_data (checksum_type, (const guchar *) str, unsigned_length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,15 @@
|
||||
# glib enables various warnings which the libcharset code wasn’t designed to
|
||||
# work with
|
||||
extra_charset_args = cc.get_supported_arguments([
|
||||
'-Wno-sign-conversion',
|
||||
])
|
||||
|
||||
charset_lib = static_library('charset', 'localcharset.c',
|
||||
include_directories : configinc,
|
||||
pic : true,
|
||||
c_args : [ '-DGLIB_CHARSETALIAS_DIR="@0@"'.format(glib_charsetaliasdir) ],
|
||||
c_args : [
|
||||
'-DGLIB_CHARSETALIAS_DIR="@0@"'.format(glib_charsetaliasdir),
|
||||
extra_charset_args,
|
||||
],
|
||||
gnu_symbol_visibility : 'hidden',
|
||||
)
|
||||
|
@ -42,29 +42,6 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static gboolean
|
||||
strv_check (const gchar * const *strv, ...)
|
||||
{
|
||||
va_list args;
|
||||
gchar *s;
|
||||
gint i;
|
||||
|
||||
va_start (args, strv);
|
||||
for (i = 0; strv[i]; i++)
|
||||
{
|
||||
s = va_arg (args, gchar*);
|
||||
if (g_strcmp0 (strv[i], s) != 0)
|
||||
{
|
||||
va_end (args);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
va_end (args);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
test_language_names (void)
|
||||
{
|
||||
@ -72,35 +49,62 @@ test_language_names (void)
|
||||
|
||||
g_setenv ("LANGUAGE", "de:en_US", TRUE);
|
||||
names = g_get_language_names ();
|
||||
g_assert (strv_check (names, "de", "en_US", "en", "C", NULL));
|
||||
g_assert_cmpstrv (names, ((const char *[]) { "de", "en_US", "en", "C", NULL }));
|
||||
|
||||
g_setenv ("LANGUAGE", "tt_RU.UTF-8@iqtelif", TRUE);
|
||||
names = g_get_language_names ();
|
||||
g_assert (strv_check (names,
|
||||
"tt_RU.UTF-8@iqtelif",
|
||||
"tt_RU@iqtelif",
|
||||
"tt.UTF-8@iqtelif",
|
||||
"tt@iqtelif",
|
||||
"tt_RU.UTF-8",
|
||||
"tt_RU",
|
||||
"tt.UTF-8",
|
||||
"tt",
|
||||
"C",
|
||||
NULL));
|
||||
g_assert_cmpstrv (names,
|
||||
((const char *[]) {
|
||||
"tt_RU.UTF-8@iqtelif",
|
||||
"tt_RU@iqtelif",
|
||||
"tt.UTF-8@iqtelif",
|
||||
"tt@iqtelif",
|
||||
"tt_RU.UTF-8",
|
||||
"tt_RU",
|
||||
"tt.UTF-8",
|
||||
"tt",
|
||||
"C",
|
||||
NULL
|
||||
}));
|
||||
}
|
||||
|
||||
static void
|
||||
test_locale_variants (void)
|
||||
{
|
||||
char **v;
|
||||
const struct
|
||||
{
|
||||
const char *locale_str;
|
||||
const char * const *expected_variants;
|
||||
}
|
||||
vectors[] =
|
||||
{
|
||||
/* Try some valid locales */
|
||||
{ "en", (const char *[]) { "en", NULL } },
|
||||
{ "sr@latin", (const char *[]) { "sr@latin", "sr", NULL } },
|
||||
{ "fr_BE", (const char *[]) { "fr_BE", "fr", NULL } },
|
||||
{ "sr_SR@latin", (const char *[]) { "sr_SR@latin", "sr@latin", "sr_SR", "sr", NULL } },
|
||||
{ "sr_SR@latin.UTF-8", (const char *[]) { "sr_SR@latin.UTF-8", "sr_SR@latin", "sr.UTF-8", "sr", NULL } },
|
||||
|
||||
v = g_get_locale_variants ("fr_BE");
|
||||
g_assert (strv_check ((const gchar * const *) v, "fr_BE", "fr", NULL));
|
||||
g_strfreev (v);
|
||||
/* And some invalid ones. The parser should try and extract what value it can */
|
||||
{ "sr@latin_invalid", (const char *[]) { "sr@latin_invalid", "sr@latin", NULL } },
|
||||
{ "sr.UTF-8@latin", (const char *[]) { "sr.UTF-8@latin", "sr@latin", "sr.UTF-8", "sr", NULL } },
|
||||
{ "sr.UTF-8_latin", (const char *[]) { "sr.UTF-8_latin", "sr.UTF-8", NULL } },
|
||||
{ "sr.UTF-8@latin_invalid", (const char *[]) { "sr.UTF-8@latin_invalid", "sr.UTF-8@latin", NULL } },
|
||||
};
|
||||
size_t i;
|
||||
|
||||
v = g_get_locale_variants ("sr_SR@latin");
|
||||
g_assert (strv_check ((const gchar * const *) v, "sr_SR@latin", "sr@latin", "sr_SR", "sr", NULL));
|
||||
g_strfreev (v);
|
||||
for (i = 0; i < G_N_ELEMENTS (vectors); i++)
|
||||
{
|
||||
char **v;
|
||||
|
||||
g_test_message ("Testing locale ‘%s’", vectors[i].locale_str);
|
||||
|
||||
v = g_get_locale_variants (vectors[i].locale_str);
|
||||
g_assert_cmpstrv (v, vectors[i].expected_variants);
|
||||
/* g_get_locale_variants() guarantees that the input is always in the output: */
|
||||
g_assert_true (g_strv_contains ((const char * const *) v, vectors[i].locale_str));
|
||||
g_strfreev (v);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -111,27 +115,27 @@ test_version (void)
|
||||
GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION,
|
||||
glib_major_version, glib_minor_version, glib_micro_version);
|
||||
|
||||
g_assert (glib_check_version (GLIB_MAJOR_VERSION,
|
||||
GLIB_MINOR_VERSION,
|
||||
GLIB_MICRO_VERSION) == NULL);
|
||||
g_assert (glib_check_version (GLIB_MAJOR_VERSION,
|
||||
GLIB_MINOR_VERSION,
|
||||
0) == NULL);
|
||||
g_assert (glib_check_version (GLIB_MAJOR_VERSION - 1,
|
||||
0,
|
||||
0) != NULL);
|
||||
g_assert (glib_check_version (GLIB_MAJOR_VERSION + 1,
|
||||
0,
|
||||
0) != NULL);
|
||||
g_assert (glib_check_version (GLIB_MAJOR_VERSION,
|
||||
GLIB_MINOR_VERSION + 1,
|
||||
0) != NULL);
|
||||
g_assert_null (glib_check_version (GLIB_MAJOR_VERSION,
|
||||
GLIB_MINOR_VERSION,
|
||||
GLIB_MICRO_VERSION));
|
||||
g_assert_null (glib_check_version (GLIB_MAJOR_VERSION,
|
||||
GLIB_MINOR_VERSION,
|
||||
0));
|
||||
g_assert_nonnull (glib_check_version (GLIB_MAJOR_VERSION - 1,
|
||||
0,
|
||||
0));
|
||||
g_assert_nonnull (glib_check_version (GLIB_MAJOR_VERSION + 1,
|
||||
0,
|
||||
0));
|
||||
g_assert_nonnull (glib_check_version (GLIB_MAJOR_VERSION,
|
||||
GLIB_MINOR_VERSION + 1,
|
||||
0));
|
||||
/* don't use + 1 here, since a +/-1 difference can
|
||||
* happen due to post-release version bumps in git
|
||||
*/
|
||||
g_assert (glib_check_version (GLIB_MAJOR_VERSION,
|
||||
GLIB_MINOR_VERSION,
|
||||
GLIB_MICRO_VERSION + 3) != NULL);
|
||||
g_assert_nonnull (glib_check_version (GLIB_MAJOR_VERSION,
|
||||
GLIB_MINOR_VERSION,
|
||||
GLIB_MICRO_VERSION + 3));
|
||||
}
|
||||
|
||||
static const gchar *argv0;
|
||||
@ -463,11 +467,11 @@ test_find_program (void)
|
||||
gsize i;
|
||||
|
||||
res = g_find_program_in_path ("sh");
|
||||
g_assert (res != NULL);
|
||||
g_assert_nonnull (res);
|
||||
g_free (res);
|
||||
|
||||
res = g_find_program_in_path ("/bin/sh");
|
||||
g_assert (res != NULL);
|
||||
g_assert_nonnull (res);
|
||||
g_free (res);
|
||||
|
||||
/* Resolve any symlinks in the CWD as that breaks the test e.g.
|
||||
@ -499,13 +503,13 @@ test_find_program (void)
|
||||
#endif
|
||||
|
||||
res = g_find_program_in_path ("this_program_does_not_exit");
|
||||
g_assert (res == NULL);
|
||||
g_assert_null (res);
|
||||
|
||||
res = g_find_program_in_path ("/bin");
|
||||
g_assert (res == NULL);
|
||||
g_assert_null (res);
|
||||
|
||||
res = g_find_program_in_path ("/etc/passwd");
|
||||
g_assert (res == NULL);
|
||||
g_assert_null (res);
|
||||
}
|
||||
|
||||
static char *
|
||||
@ -789,7 +793,7 @@ test_username (void)
|
||||
|
||||
name = g_get_user_name ();
|
||||
|
||||
g_assert (name != NULL);
|
||||
g_assert_nonnull (name);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -799,7 +803,7 @@ test_realname (void)
|
||||
|
||||
name = g_get_real_name ();
|
||||
|
||||
g_assert (name != NULL);
|
||||
g_assert_nonnull (name);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -809,7 +813,7 @@ test_hostname (void)
|
||||
|
||||
name = g_get_host_name ();
|
||||
|
||||
g_assert (name != NULL);
|
||||
g_assert_nonnull (name);
|
||||
g_assert_true (g_utf8_validate (name, -1, NULL));
|
||||
}
|
||||
|
||||
@ -899,11 +903,11 @@ test_desktop_special_dir (void)
|
||||
const gchar *dir, *dir2;
|
||||
|
||||
dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
|
||||
g_assert (dir != NULL);
|
||||
g_assert_nonnull (dir);
|
||||
|
||||
g_reload_user_special_dirs_cache ();
|
||||
dir2 = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
|
||||
g_assert (dir2 != NULL);
|
||||
g_assert_nonnull (dir2);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -970,11 +974,11 @@ test_clear_pointer (void)
|
||||
|
||||
a = g_malloc (5);
|
||||
g_clear_pointer (&a, g_free);
|
||||
g_assert (a == NULL);
|
||||
g_assert_null (a);
|
||||
|
||||
a = g_malloc (5);
|
||||
(g_clear_pointer) (&a, g_free);
|
||||
g_assert (a == NULL);
|
||||
g_assert_null (a);
|
||||
}
|
||||
|
||||
/* Test that g_clear_pointer() works with a GDestroyNotify which contains a cast.
|
||||
@ -1046,15 +1050,15 @@ test_take_pointer (void)
|
||||
get_obj (NULL);
|
||||
|
||||
get_obj (&a);
|
||||
g_assert (a);
|
||||
g_assert_nonnull (a);
|
||||
|
||||
/* ensure that it works to skip the macro */
|
||||
b = (g_steal_pointer) (&a);
|
||||
g_assert (!a);
|
||||
g_assert_null (a);
|
||||
obj_count--;
|
||||
g_free (b);
|
||||
|
||||
g_assert (!obj_count);
|
||||
g_assert_cmpint (obj_count, ==, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1063,16 +1067,16 @@ test_misc_mem (void)
|
||||
gpointer a;
|
||||
|
||||
a = g_try_malloc (0);
|
||||
g_assert (a == NULL);
|
||||
g_assert_null (a);
|
||||
|
||||
a = g_try_malloc0 (0);
|
||||
g_assert (a == NULL);
|
||||
g_assert_null (a);
|
||||
|
||||
a = g_malloc (16);
|
||||
a = g_try_realloc (a, 20);
|
||||
a = g_try_realloc (a, 0);
|
||||
|
||||
g_assert (a == NULL);
|
||||
g_assert_null (a);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1209,11 +1213,11 @@ test_nullify (void)
|
||||
{
|
||||
gpointer p = &test_nullify;
|
||||
|
||||
g_assert (p != NULL);
|
||||
g_assert_nonnull (p);
|
||||
|
||||
g_nullify_pointer (&p);
|
||||
|
||||
g_assert (p == NULL);
|
||||
g_assert_null (p);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1241,7 +1245,7 @@ test_check_setuid (void)
|
||||
gboolean res;
|
||||
|
||||
res = GLIB_PRIVATE_CALL(g_check_setuid) ();
|
||||
g_assert (!res);
|
||||
g_assert_false (res);
|
||||
}
|
||||
|
||||
/* Test the defined integer limits are correct, as some compilers have had
|
||||
|
Loading…
x
Reference in New Issue
Block a user