bug-gawk
[Top][All Lists]
Advanced

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

Re: Internal error with gawk-5.3.0


From: Miguel Pineiro Jr.
Subject: Re: Internal error with gawk-5.3.0
Date: Sun, 07 Jan 2024 16:34:07 -0500
User-agent: Cyrus-JMAP/3.9.0-alpha0-1364-ga51d5fd3b7-fm-20231219.001-ga51d5fd3

On Sun, Jan 7, 2024, at 2:34 PM, arnold@skeeve.com wrote:
> The attached patch seems to do the trick for me.

Agreed. I was testing the same fix with two minor differences. The size of the 
allocation is strictly sizeof size_t. And I changed ezalloc to emalloc when 
allocating for ptr.

I don't see any reason to zero when every byte that's allocated will be written 
to by the populating loop (and by the fix in the patch). I notice a 5% speedup 
on the following (admittedly contrived) microbenchmark after switching to 
emalloc:

#!/bin/sh

awk=${1:-./gawk}

$awk '
BEGIN {
        for (i=0; i<20000000; i++) {
                a[0] = "abcdefghi"
                match(a[0], /xyz/)
                delete a[0]
        }
}
'


diff --git a/node.c b/node.c
index de12f05d..887957f2 100644
--- a/node.c
+++ b/node.c
@@ -821,8 +821,13 @@ str2wstr(NODE *n, size_t **ptr)
         * This also avoids future double-free errors while releasing
         * shallow copies, eg. *tmp = *Null_field; free_wstr(tmp);
         */
-       if (n == Nnull_string || n == Null_field)
+       if (n == Nnull_string || n == Null_field) {
+               if (ptr != NULL) {
+                       emalloc(*ptr, size_t *, sizeof(size_t), "str2wstr");
+                       **ptr = 0;
+               }
                return n;
+       }
 
        if ((n->flags & WSTRCUR) != 0) {
                if (ptr == NULL)
@@ -857,7 +862,7 @@ str2wstr(NODE *n, size_t **ptr)
         * Create the array.
         */
        if (ptr != NULL) {
-               ezalloc(*ptr, size_t *, sizeof(size_t) * (n->stlen + 1), 
"str2wstr");
+               emalloc(*ptr, size_t *, sizeof(size_t) * (n->stlen + 1), 
"str2wstr");
        }
 
        sp = n->stptr;



reply via email to

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