Re: expand_string_buf, switch (*p), default case

Dmitry Goncharov <[email protected]> Wed, 3 Dec 2025 17:24:23 -0500
Newsgroups gmane.comp.gnu.make.general
Message-ID <CAG+Z0CsLu6bkUvhU-P=TjTuj+QZqce=MCdKM1HVXRT9ZPpndNA@mail.gmail.com>
On Sat, Nov 29, 2025 at 4:30=E2=80=AFPM Dimitar Dimitrov <mail.mitko@gmail.=
com> wrote:
>
> Hello,
> In `expand.c::expand_string_buf` there is a `switch (*p)` and in its
> default case, there is
> ```
> if (ISSPACE (p[-1]))
>     break;
> ```
> It seems to me that, at that point in the code, `p[-1]` is always `$`

You are right.
Maybe this check was needed in a prior revision.

diff --git a/src/expand.c b/src/expand.c
index d14feba7..647b1fe8 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -554,8 +554,7 @@ expand_string_buf (char *buf, const char *string,
size_t length)
           break;

         default:
-          if (ISSPACE (p[-1]))
-            break;
+          assert (p[-1] =3D=3D '$');

           /* A $ followed by a random char is a variable reference:
              $a is equivalent to $(a).  */

regards, Dmitry