Clamp value index by number of values

* This can be out of bounds when purely considering the instruction index if
  there's an instruction near the end, beyond the point where there are (many)
  further values.
This commit is contained in:
baldurk
2021-09-24 15:11:22 +01:00
parent ff92cc2ba3
commit e1880f62ab
@@ -754,7 +754,7 @@ const Constant *ProgramEditor::GetOrAddConstant(Function *f, const Constant &c)
Instruction *ProgramEditor::AddInstruction(Function *f, size_t idx, const Instruction &inst)
{
size_t valueIdx = f->constants.size() + idx;
size_t valueIdx = RDCMIN(f->values.size() - 1, f->constants.size() + idx);
if(inst.type != m_VoidType)
{
// find the value index for the instruction we're inserting before. This won't match up exactly