gio: Fix various implicit conversions from size_t to smaller types

Basically various trivial instances of the following MSVC compiler
warning:
```
../gio/gio-tool-set.c(50): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall 2024-04-25 00:37:47 +01:00
parent c378a5a049
commit 6e362ce3b6
No known key found for this signature in database
GPG Key ID: DCDF5885B1F3ED73
20 changed files with 44 additions and 37 deletions

View File

@ -666,8 +666,8 @@ const gchar *
g_application_command_line_getenv (GApplicationCommandLine *cmdline,
const gchar *name)
{
gint length = strlen (name);
gint i;
size_t length = strlen (name);
size_t i;
/* TODO: expand on windows */
if (cmdline->priv->environ)

View File

@ -1373,7 +1373,7 @@ dump_method (const GDBusMethodInfo *o,
{
guint n;
guint m;
guint name_len;
size_t name_len;
guint total_num_args;
for (n = 0; o->annotations != NULL && o->annotations[n] != NULL; n++)

View File

@ -3822,8 +3822,8 @@ static gboolean
namespace_rule_matches (const gchar *namespace,
const gchar *name)
{
gint len_namespace;
gint len_name;
size_t len_namespace;
size_t len_name;
len_namespace = strlen (namespace);
len_name = strlen (name);
@ -3841,7 +3841,7 @@ static gboolean
path_rule_matches (const gchar *path_a,
const gchar *path_b)
{
gint len_a, len_b;
size_t len_a, len_b;
len_a = strlen (path_a);
len_b = strlen (path_b);

View File

@ -543,7 +543,8 @@ match_matches (GDBusDaemon *daemon,
{
MatchElement *element;
Name *name;
int i, len, len2;
int i;
size_t len, len2;
const char *value;
int check_type;

View File

@ -2852,7 +2852,7 @@ append_value_to_blob (GVariant *value,
const gchar *signature;
child = g_variant_get_child_value (value, 0);
signature = g_variant_get_type_string (child);
g_memory_buffer_put_byte (mbuf, strlen (signature));
g_memory_buffer_put_byte (mbuf, (guint8) strlen (signature)); /* signature is already validated to be this short */
g_memory_buffer_put_string (mbuf, signature);
g_memory_buffer_put_byte (mbuf, '\0');
if (!append_value_to_blob (child,

View File

@ -113,7 +113,7 @@ is_valid_name (const gchar *start,
gboolean
g_dbus_is_name (const gchar *string)
{
guint len;
size_t len;
gboolean ret;
const gchar *s;

View File

@ -239,7 +239,7 @@ static const char *
match_prefix (const char *path,
const char *prefix)
{
int prefix_len;
size_t prefix_len;
prefix_len = strlen (prefix);
if (strncmp (path, prefix, prefix_len) != 0)

View File

@ -345,7 +345,7 @@ init_completion (GFilenameCompleter *completer,
GFile *file, *parent;
char *basename;
char *t;
int len;
size_t len;
*basename_out = NULL;

View File

@ -89,7 +89,7 @@ prompt_for (const char *prompt, const char *default_value, gboolean echo)
gboolean restore_flags;
#endif
char data[256];
int len;
size_t len;
if (default_value && *default_value != 0)
g_print ("%s [%s]: ", prompt, default_value);

View File

@ -42,10 +42,10 @@ static const GOptionEntry entries[] = {
static char *
hex_unescape (const char *str)
{
int i;
size_t i;
char *unescaped_str, *p;
unsigned char c;
int len;
size_t len;
len = strlen (str);
unescaped_str = g_malloc (len + 1);

View File

@ -680,7 +680,7 @@ key_state_serialise (KeyState *state)
if (state->l10n_context)
{
gint len;
size_t len;
/* Contextified messages are supported by prepending
* the context, followed by '\004' to the start of the

View File

@ -479,7 +479,7 @@ static const char *
match_prefix (const char *path,
const char *prefix)
{
int prefix_len;
size_t prefix_len;
prefix_len = strlen (prefix);
if (strncmp (path, prefix, prefix_len) != 0)

View File

@ -83,7 +83,7 @@ list_resource (GResource *resource,
gint i;
gchar *child;
GError *error = NULL;
gint len;
size_t len;
children = g_resource_enumerate_children (resource, path, 0, &error);
if (error)

View File

@ -352,7 +352,7 @@ g_resource_find_overlay (const gchar *path,
/* This is a null-terminated array of replacement strings (with '=' inside) */
static const gchar * const *overlay_dirs;
gboolean res = FALSE;
gint path_len = -1;
size_t path_len = 0;
gint i;
/* We try to be very fast in case there are no overlays. Otherwise,
@ -449,9 +449,9 @@ g_resource_find_overlay (const gchar *path,
for (i = 0; overlay_dirs[i]; i++)
{
const gchar *src;
gint src_len;
size_t src_len;
const gchar *dst;
gint dst_len;
size_t dst_len;
gchar *candidate;
{
@ -466,7 +466,7 @@ g_resource_find_overlay (const gchar *path,
/* hold off on dst_len because we will probably fail the checks below */
}
if (path_len == -1)
if (i == 0)
path_len = strlen (path);
/* The entire path is too short to match the source */

View File

@ -354,7 +354,7 @@ static const char *
match_prefix (const char *path,
const char *prefix)
{
int prefix_len;
size_t prefix_len;
prefix_len = strlen (prefix);
if (strncmp (path, prefix, prefix_len) != 0)

View File

@ -472,15 +472,21 @@ g_unix_socket_address_new_with_type (const gchar *path,
{
GSocketAddress *address;
GByteArray *array;
size_t path_len_unsigned;
if (type == G_UNIX_SOCKET_ADDRESS_ANONYMOUS)
path_len = 0;
else if (path_len == -1)
path_len = strlen (path);
path_len_unsigned = 0;
else if (path_len < 0)
path_len_unsigned = strlen (path);
else
path_len_unsigned = (size_t) path_len;
array = g_byte_array_sized_new (path_len);
/* The code below cant handle anything longer. */
g_return_val_if_fail (path_len_unsigned <= G_MAXUINT, NULL);
g_byte_array_append (array, (guint8 *)path, path_len);
array = g_byte_array_sized_new (path_len_unsigned);
g_byte_array_append (array, (guint8 *)path, path_len_unsigned);
address = g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS,
"path-as-array", array,

View File

@ -63,7 +63,7 @@ test_read_lines (GDataStreamNewlineType newline_type)
GError *error = NULL;
gpointer data;
char *lines;
int size;
size_t size;
int i;
#define TEST_STRING "some_text"
@ -99,7 +99,7 @@ test_read_lines (GDataStreamNewlineType newline_type)
/* compare data */
size = strlen (data);
g_assert_cmpint (size, <, MAX_LINES_BUFF);
g_assert_cmpuint (size, <, MAX_LINES_BUFF);
g_assert_cmpstr ((char*)data, ==, lines);
g_object_unref (base_stream);

View File

@ -1470,7 +1470,7 @@ test_run_in_thread_overflow (void)
GCancellable *cancellable;
GTask *task;
gchar buf[NUM_OVERFLOW_TASKS + 1];
gint i;
size_t i;
/* Queue way too many tasks and then sleep for a bit. The first 10
* tasks will be dispatched to threads and will then block on
@ -1516,13 +1516,13 @@ test_run_in_thread_overflow (void)
* plausibly get (and we hope that if gtask is actually broken then
* it will exceed those limits).
*/
g_assert_cmpint (i, >=, 10);
g_assert_cmpuint (i, >=, 10);
if (g_test_slow ())
g_assert_cmpint (i, <, 50);
g_assert_cmpuint (i, <, 50);
else
g_assert_cmpint (i, <, 20);
g_assert_cmpuint (i, <, 20);
g_assert_cmpint (i + strspn (buf + i, "X"), ==, NUM_OVERFLOW_TASKS);
g_assert_cmpuint (i + strspn (buf + i, "X"), ==, NUM_OVERFLOW_TASKS);
}
/* test_return_on_cancel */

View File

@ -160,8 +160,8 @@ g_win32_fs_monitor_callback (DWORD error,
if (monitor->isfile)
{
gint long_filename_length = wcslen (monitor->wfilename_long);
gint short_filename_length = wcslen (monitor->wfilename_short);
size_t long_filename_length = wcslen (monitor->wfilename_long);
size_t short_filename_length = wcslen (monitor->wfilename_short);
enum GWin32FileMonitorFileAlias alias_state;
/* If monitoring a file, check that the changed file

View File

@ -318,7 +318,7 @@ static const char *
match_prefix (const char *path,
const char *prefix)
{
int prefix_len;
size_t prefix_len;
prefix_len = strlen (prefix);
if (strncmp (path, prefix, prefix_len) != 0)