From a5682aff2ea63fe453dc4ee1fb4a9a18b5b6109b Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 7 Nov 2024 13:49:51 +0000 Subject: [PATCH] goption: Fix string length handling to use size_t type When parsing command line options, use `size_t` to hold string lengths. This introduces no functional changes (any strings long enough to fit in `size_t` but not in `int` will probably hit command line length limits), but it does fix a `-Wshorten-64-to-32` warning. Signed-off-by: Philip Withnall Helps: #3527 --- glib/goption.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/glib/goption.c b/glib/goption.c index f9bae854f..4e47d42c5 100644 --- a/glib/goption.c +++ b/glib/goption.c @@ -1950,13 +1950,14 @@ g_option_context_parse (GOptionContext *context, } else { /* short option */ - gint new_i = i, arg_length; + gint new_i = i; + size_t arg_length; gboolean *nulled_out = NULL; gboolean has_h_entry = context_has_h_entry (context); arg = (*argv)[i] + 1; arg_length = strlen (arg); nulled_out = g_newa0 (gboolean, arg_length); - for (int j = 0; j < arg_length; j++) + for (size_t j = 0; j < arg_length; j++) { if (context->help_enabled && (arg[j] == '?' || (arg[j] == 'h' && !has_h_entry))) @@ -1995,7 +1996,7 @@ g_option_context_parse (GOptionContext *context, { gchar *new_arg = NULL; gint arg_index = 0; - for (int j = 0; j < arg_length; j++) + for (size_t j = 0; j < arg_length; j++) { if (!nulled_out[j]) {