Thanks for considering (when the time is right),

but in the meantime I found a technical problem with my patch, so I am
replacing it with a correct one (please ignore the older one).

The problem was assigning to an integer from a long result was plain
wrong, because ERANGE checking in strtol() was done not for the intended
integer range but of course for long int range.

I am now working on my first test cases to verify all edge cases for
invalid register numbers lead to the same error message.

I will append them here when they are ready.

Heiko

On 11/22/24 4:48 PM, Jeff Law wrote:


On 11/22/24 7:40 AM, Heiko Eißfeldt wrote:
A simple replacement of atoi() with strtol() in
varasm.cc:decode_reg_name_and_count().
Parsing now has errno ERANGE checking, eg no undetected overflow.

Being new it is difficult for me to come up with a good test case.
So I don't see any technical problem with the patch, but we don't have
any evidence there's any kind of bug here.  I guess if a port had a
bogus register name we could trigger a problem.

Given we're in stage3 (bugfixing) in preparation for the gcc-15
release in the spring, I'm going to defer this patch.

Jeff

diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index acc4b4a0419..ee9df83e0e1 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -993,9 +993,12 @@ decode_reg_name_and_count (const char *asmspec, int 
*pnregs)
          break;
       if (asmspec[0] != 0 && i < 0)
        {
-         i = atoi (asmspec);
-         if (i < FIRST_PSEUDO_REGISTER && i >= 0 && reg_names[i][0])
-           return i;
+         char *pend{};
+         errno = 0;
+         long j = strtol (asmspec, &pend, 10);
+         if (errno != ERANGE && j <= INT_MAX
+             && j < FIRST_PSEUDO_REGISTER && j >= 0 && reg_names[j][0])
+           return j;
          else
            return -2;
        }

Reply via email to