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