Pádraig Brady wrote:
> diff --git a/lib/canonicalize.c b/lib/canonicalize.c
> index 49eaffd4f1..adbccaac87 100644
> --- a/lib/canonicalize.c
> +++ b/lib/canonicalize.c
> @@ -208,6 +208,13 @@ canonicalize_filename_mode_stk (const char *name,
> canonicalize_mode_t can_mode,
> char *dest;
> char const *start;
>
> + bool logical = (can_mode & CAN_NOLINKS) != 0;
> +
> + int num_links = 0;
> + Hash_table *ht = NULL;
> + bool end_in_extra_buffer = false;
> + bool failed = true;
> +
> if (!IS_ABSOLUTE_FILE_NAME (name))
> {
> while (!getcwd (bufs->rname.data, bufs->rname.length))
> @@ -271,13 +278,6 @@ canonicalize_filename_mode_stk (const char *name,
> canonicalize_mode_t can_mode,
> start = name + prefix_len;
> }
>
> - bool logical = (can_mode & CAN_NOLINKS) != 0;
> -
> - int num_links = 0;
> - Hash_table *ht = NULL;
> - bool end_in_extra_buffer = false;
> - bool failed = true;
> -
> for (; *start;)
> {
> /* Skip sequence of multiple file name separators. */
For 2 out of the 5 variables, this is necessary, indeed. However, the scope
of the other 3 variables can be reduced again.
And the same mistake exists in canonicalized-lgpl.c.
Thanks for noticing this.
From 90fb2da6667f7f98f29d64784e0a274759f041d5 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Wed, 10 Dec 2025 19:06:14 +0100
Subject: [PATCH 1/2] canonicalize: Reduce scope of local variables.
* lib/canonicalize.c (canonicalize_filename_mode_stk): Reduce scope of
'logical', 'num_links', 'end_in_extra_buffer'.
---
ChangeLog | 6 ++++++
lib/canonicalize.c | 9 +++++----
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a813d38413..29c9a04020 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-12-10 Bruno Haible <[email protected]>
+
+ canonicalize: Reduce scope of local variables.
+ * lib/canonicalize.c (canonicalize_filename_mode_stk): Reduce scope of
+ 'logical', 'num_links', 'end_in_extra_buffer'.
+
2025-12-10 P??draig Brady <[email protected]>
canonicalize: fix UMR introduced in recent change
diff --git a/lib/canonicalize.c b/lib/canonicalize.c
index adbccaac87..240252fb2c 100644
--- a/lib/canonicalize.c
+++ b/lib/canonicalize.c
@@ -208,11 +208,7 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
char *dest;
char const *start;
- bool logical = (can_mode & CAN_NOLINKS) != 0;
-
- int num_links = 0;
Hash_table *ht = NULL;
- bool end_in_extra_buffer = false;
bool failed = true;
if (!IS_ABSOLUTE_FILE_NAME (name))
@@ -278,6 +274,11 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
start = name + prefix_len;
}
+ bool logical = (can_mode & CAN_NOLINKS) != 0;
+
+ int num_links = 0;
+ bool end_in_extra_buffer = false;
+
for (; *start;)
{
/* Skip sequence of multiple file name separators. */
--
2.52.0
>From 5b5b8ea6556aee0987248d43d638f7e97f991053 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Wed, 10 Dec 2025 19:06:32 +0100
Subject: [PATCH 2/2] canonicalize-lgpl: Fix UMR introduced in recent change.
* lib/canonicalize-lgpl.c (realpath_stk): Move declaration of 'failed'
before first 'goto'.
---
ChangeLog | 4 ++++
lib/canonicalize-lgpl.c | 3 ++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 29c9a04020..52ac60d385 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2025-12-10 Bruno Haible <[email protected]>
+ canonicalize-lgpl: Fix UMR introduced in recent change.
+ * lib/canonicalize-lgpl.c (realpath_stk): Move declaration of 'failed'
+ before first 'goto'.
+
canonicalize: Reduce scope of local variables.
* lib/canonicalize.c (canonicalize_filename_mode_stk): Reduce scope of
'logical', 'num_links', 'end_in_extra_buffer'.
diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c
index cddf2ff36e..ed89ec4f67 100644
--- a/lib/canonicalize-lgpl.c
+++ b/lib/canonicalize-lgpl.c
@@ -218,6 +218,8 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
char *dest;
char const *start;
+ bool failed = true;
+
if (!IS_ABSOLUTE_FILE_NAME (name))
{
while (!__getcwd (bufs->rname.data, bufs->rname.length))
@@ -252,7 +254,6 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
int num_links = 0;
bool end_in_extra_buffer = false;
- bool failed = true;
for (; *start;)
{
--
2.52.0