From: Paul Eggert Date: Thu, 27 Apr 2023 00:14:54 +0000 (-0700) Subject: chmod: pacify GCC 13 X-Git-Tag: v9.4~146 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c199713ed384d58e23671f58f646afcf06fabf8;p=thirdparty%2Fcoreutils.git chmod: pacify GCC 13 * src/chmod.c (main): Use xpalloc instead of X2REALLOC, and make the corresponding variables signed instead of unsigned. When reallocating the buffer, this grows it by a factor of 1.5, not 2. This also pacifies gcc -Wanalyzer-null-dereference. --- diff --git a/src/chmod.c b/src/chmod.c index e48736e119..477d9f9e4e 100644 --- a/src/chmod.c +++ b/src/chmod.c @@ -417,8 +417,8 @@ int main (int argc, char **argv) { char *mode = NULL; - size_t mode_len = 0; - size_t mode_alloc = 0; + idx_t mode_len = 0; + idx_t mode_alloc = 0; bool ok; bool preserve_root = false; char const *reference_file = NULL; @@ -468,14 +468,13 @@ main (int argc, char **argv) comma, and the new string (e.g., "-s,-rwx"). */ char const *arg = argv[optind - 1]; - size_t arg_len = strlen (arg); - size_t mode_comma_len = mode_len + !!mode_len; - size_t new_mode_len = mode_comma_len + arg_len; + idx_t arg_len = strlen (arg); + idx_t mode_comma_len = mode_len + !!mode_len; + idx_t new_mode_len = mode_comma_len + arg_len; + assume (0 <= new_mode_len); /* Pacify GCC bug #109613. */ if (mode_alloc <= new_mode_len) - { - mode_alloc = new_mode_len + 1; - mode = X2REALLOC (mode, &mode_alloc); - } + mode = xpalloc (mode, &mode_alloc, + new_mode_len + 1 - mode_alloc, -1, 1); mode[mode_len] = ','; memcpy (mode + mode_comma_len, arg, arg_len + 1); mode_len = new_mode_len;