diff mbox series

replace atoi with strtol in varasm.cc (decode_reg_name_and_count) [PR114540]

Message ID b21aeafb-8222-497a-a976-5727e85f225d@hexco.de
State New
Headers show
Series replace atoi with strtol in varasm.cc (decode_reg_name_and_count) [PR114540] | expand

Commit Message

Heiko Eißfeldt Nov. 22, 2024, 2:40 p.m. UTC
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.
---

             return -2;

Comments

Jeff Law Nov. 22, 2024, 3:48 p.m. UTC | #1
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 mbox series

Patch

diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index acc4b4a0419..d3c60eaf4d6 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -993,8 +993,11 @@  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])
+         char *pend{};
+         errno = 0;
+         i = strtol (asmspec, &pend, 10);
+         if (errno != ERANGE
+             && i < FIRST_PSEUDO_REGISTER && i >= 0 && reg_names[i][0])
             return i;
           else