diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc index b6099ff4d0..c88358a9cb 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc @@ -1443,6 +1443,9 @@ void ActionFuncLink::funcLinkInput(FuncCallSpecs *fc,Funcdata &data) ProtoParameter *param = fc->getParam(i); active->registerTrial(param->getAddress(),param->getSize()); active->getTrial(i).markActive(); // Parameter is not optional + if (varargs){ + active->getTrial(i).setFixedPosition(i); + } AddrSpace *spc = param->getAddress().getSpace(); uintb off = param->getAddress().getOffset(); int4 sz = param->getSize(); diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc index 0526ed04c7..64c6379777 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc @@ -1701,6 +1701,25 @@ bool ParamTrial::operator<(const ParamTrial &b) const return (size < b.size); } +/// Sort by fixed position then by ParamTrial::operator< +/// \param a trial +/// \param b trial +/// \return \b true if \b a should be ordered before \b b +bool ParamTrial::fixedPositionCompare(const ParamTrial &a, const ParamTrial &b) + +{ + if (a.fixedPosition == -1 && b.fixedPosition == -1){ + return a < b; + } + if (a.fixedPosition == -1){ + return false; + } + if (b.fixedPosition == -1){ + return true; + } + return a.fixedPosition < b.fixedPosition; +} + /// \param recoversub selects whether a sub-function or the active function is being tested ParamActive::ParamActive(bool recoversub) @@ -5326,6 +5345,12 @@ void FuncCallSpecs::buildInputFromTrials(Funcdata &data) newparam.push_back(op->getIn(0)); // Preserve the fspec parameter + if (isDotdotdot() && isInputLocked()){ + //if varargs, move the fixed args to the beginning of the list in order + //preserve relative order of variable args + activeinput.sortFixedPosition(); + } + for(int4 i=0;i