summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2023-04-26 17:14:54 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2023-04-26 18:20:19 -0700
commit6c199713ed384d58e23671f58f646afcf06fabf8 (patch)
treecb1fa9982b94a814decf6d5ad4039d8d8b117dbb
parentd178b497542b19571dd6896db561c46ec2e451c3 (diff)
downloadcoreutils-6c199713ed384d58e23671f58f646afcf06fabf8.tar.gz
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.
-rw-r--r--src/chmod.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/chmod.c b/src/chmod.c
index e48736e11..477d9f9e4 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;