bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gensub() indirectly called with more than 2 parameters: produce a st


From: arnold
Subject: Re: gensub() indirectly called with more than 2 parameters: produce a strange error
Date: Wed, 22 Jan 2025 08:55:35 -0700
User-agent: Heirloom mailx 12.5 7/5/10

"Andrew J. Schorr" <aschorr@telemetry-investments.com> wrote:

> Hi,
>
> Is that the issue, or is it that the indirect gensub call
> is requiring 2 args instead of 3 or 4?
>
> In builtin.c:call_sub, the code says: ...

The issue is that indirect gensub should take 3 or 4 arguments;
the code is going through the wrong code path. I missed that
this was the problem.

The fix is below. A similar fix is needed for split/patsplit
when preceded by awk:: and called indirectly. This patch
addresses both.

Thanks,

Arnold
-----------------------------------------
diff --git a/builtin.c b/builtin.c
index adb5c0fb..f39c274c 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2212,9 +2212,13 @@ call_sub(const char *name, int nargs)
        NODE **lhs, *rhs;
        NODE *zero = make_number(0.0);
        NODE *result;
+       const char *fname = name;
 
-       if (name[0] == 'g') {
-               if (name[1] == 'e')
+       if (fname[0] == 'a')    // awk::...
+               fname += 5;
+
+       if (fname[0] == 'g') {
+               if (fname[1] == 'e')
                        flags = GENSUB;
                else
                        flags = GSUB;
@@ -2350,12 +2354,16 @@ call_split_func(const char *name, int nargs)
 {
        NODE *regex, *seps;
        NODE *result;
+       const char *fname = name;
 
        regex = seps = NULL;
        if (nargs < 2 || nargs > 4)
                fatal(_("indirect call to %s requires two to four arguments"),
                                name);
 
+       if (fname[0] == 'a')    // awk::...
+               fname += 5;
+
        if (nargs == 4)
                seps = POP();
 
@@ -2369,7 +2377,7 @@ call_split_func(const char *name, int nargs)
                        need_free = true;
                }
        } else {
-               if (name[0] == 's') {
+               if (fname[0] == 's') {
                        regex = make_regnode(Node_regex, FS_node->var_value);
                        regex->re_flags |= FS_DFLT;
                } else
@@ -2386,7 +2394,7 @@ call_split_func(const char *name, int nargs)
        if (seps)
                PUSH(seps);
 
-       result = (name[0] == 's') ? do_split(nargs) : do_patsplit(nargs);
+       result = (fname[0] == 's') ? do_split(nargs) : do_patsplit(nargs);
 
        if (need_free) {
                refree(regex->re_reg[0]);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]