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.
---

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
            return -2;


Reply via email to