Examples of errors detected by the V3061 diagnostic.


V3061. Parameter 'A' is always rewritten in method body before being used.


Xenko

V3061 Parameter 'internalEvent' is always rewritten in method body before being used. SiliconStudio.Xenko ParameterCollection.cs 1158


internal delegate void InternalValueChangedDelegate(
  InternalValue internalValue, object oldValue);

private static InternalValueChangedDelegate
CreateInternalValueChangedEvent(
  ParameterKey key,
  InternalValueChangedDelegate internalEvent,
  ValueChangedDelegate originalEvent)
{
    internalEvent = (internalValue, oldValue) =>
      originalEvent(key, internalValue, oldValue);
    return internalEvent;
}

Xenko

V3061 Parameter 'libraryData' is always rewritten in method body before being used. SiliconStudio.TextureConverter DxtTexLib.cs 213


private void Load(TexImage image,
                         DxtTextureLibraryData libraryData,
                         LoadingRequest loader)
{
  ....
  libraryData = new DxtTextureLibraryData(); // <=
  image.LibraryData[this] = libraryData;

  libraryData.Image = new ScratchImage();
  ....
}

Similar errors can be found in some other places:

  • V3061 Parameter 'libraryData' is always rewritten in method body before being used. SiliconStudio.TextureConverter FITexLib.cs 244

Accord.Net

V3061 Parameter 'mode' is always rewritten in method body before being used. Accord.Statistics TriangularDistribution.cs 646


private static double WeightedMode(double[] observations,
                                   double[] weights,
                                   double mode,
                                   int imax,
                                   int imin)
{
  ....
  var bestValue = currentValue;
  ....
  mode = bestValue;
  return mode;
}

Similar errors can be found in some other places:

  • V3061 Parameter 'mode' is always rewritten in method body before being used. Accord.Statistics TriangularDistribution.cs 678
  • V3061 Parameter 'mode' is always rewritten in method body before being used. Accord.Statistics TriangularDistribution.cs 706
  • V3061 Parameter 'mode' is always rewritten in method body before being used. Accord.Statistics TriangularDistribution.cs 735

Old NASA World Wind (C#)

V3061 Parameter 'fDistance' is always rewritten in method body before being used. GPSTrackerPlugin.WorldWind.cs 1667


void ShowInfo(.... , float fDistance )
{
  ....
  if (m_fTotalDistance>=0F)
  {
    string sUnit=(m_fTotalDistance>=1F)?"km":"m";
    fDistance = (m_fTotalDistance < 1F) ?
                (m_fTotalDistance * 1000F) :
                 m_fTotalDistance;
    sInfo += "Track Distance: " +
              Convert.ToString(
               decimal.Round(
                Convert.ToDecimal(fDistance),3)) +
              sUnit +
              "\n";
  }
  ....
}

MSBuild

V3061 Parameter 'numericValue' is always rewritten in method body before being used. NodePacketTranslator.cs 320


public void TranslateEnum<T>(ref T value, int numericValue)
{
  numericValue = _reader.ReadInt32();  // <=
  Type enumType = value.GetType();
  value = (T)Enum.ToObject(enumType, numericValue);
}

Similar errors can be found in some other places:

  • V3061 Parameter 'defaultToolsVersion' is always rewritten in method body before being used. ToolsetProvider.cs 118

Mono

V3061 Parameter 'errorInfo' is always rewritten in method body before being used. corlib-net_4_x Marshal.cs 1552


internal static int SetErrorInfo (int dwReserved,
                                  IErrorInfo errorInfo)
{
  int retVal = 0;
  errorInfo = null;  // <=

  ....
  retVal = _SetErrorInfo (dwReserved, errorInfo);
  ....
}


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++ and C#

goto PVS-Studio;