<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/95776>95776</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Buffer overflow at X86FloatingPoint.cpp
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
DyadyaMops
</td>
</tr>
</table>
<pre>
```cpp
for (unsigned I = 0; I < N; ++I)
pushReg(N - I - 1);
```
There is a buffer overflow error in the code, since the Reg value may
exceed the size of the RegMap array, which leads to an outflow of the
array boundaries. Checking for stackTop (see below) does not protect against this case,
since it checks only the Stack array, not the RegMap. It is necessary
to add a check of the range of Reg values before calling pushReg
to make sure that Reg is within acceptable limits.
```cpp
void pushReg(unsigned Reg) {
assert(Reg < NumFPRegs && "Register number out of range!");
if (StackTop >= 8)
report_fatal_error("Stack overflow!");
Stack[StackTop] = Reg;
RegMap[Reg] = StackTop++;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVMGO4jgQ_RrnUmoUHAjJIYehWaQ-zGjUM4e9jSpOJfG2sSOXA8t-_coO0NO9GyGI7apX9V49g8x6sESN2O7F9pDhHEbnm8MVuyt-dRNnreuujcgPIv9y-y7z5aOmCZat3nkQspptAuvgBURxgFwU-_T6DN_iq5B7IfcvQtZLFgDANPP4SoOQ1Td4ghd4gnU8L_afai3LnyN5As2A0M59Tx7cmXxv3AXIe-dBWwgjgXIdCfkMrK2itPNKA5zRzAQnvC5g9Lci6tIp638IXH-P_IoToPd4jRiXUasRDGHHEBygBTeHVHJJWMBSOLRuth16TbyC55HUm7YDRHE4oHr76aaoEhNBS8ZdhKyhc8RgXYDJu0AqAA6oLQcIo2ZQyJHHUmIhowOoiMzgrLmmjn9E8PeGI9o7kRW8hKiYJUXM6G_kI5OuA1zA7tw92iEJ8ZCLoaXeeQKFxkQ294HdUU74RsCzjzJjSIma4aLDqC2gUjQFbA2B0ScdePVfC928cHa6-80NDyulZQ1id3MEIDP5IGQVSyVvzafj91caGIQshSxBSPlKg-ZAHux8aqNN5hBpJX5CroWUv7sM0qP7OJ0fj0kVf0QTVx_sGh9Pk_PhV48Bza9kOyErIeUyhrsh_6dKChDb_b2E2B7SPYkUP7ayjE5s9_HoFvXISrfoQ4LYHW6Lh7BZ1xRdXdSYUbPeratS7upNkY1NW65RdeUm37ZYYk-qqvtaUrujdrOp2z7TjczlJi_Xu7Us6rxYVUi47rHCKq_VuqzFJqcTarMy5nxaOT9kmnmmpt7udmVmsCXD6e9ESksXSIdRiu0h803MeWrngcUmN5oDv6MEHQw1-0_3GgP8WZVH4zBoO3x32oaVmqZs9qYZQ5hYFF-EPAp5HHQY53al3EnIY0S9_TxN3v1FKgh5TL2wkMel13Mj_w0AAP__OhSKUw">