Examples of errors detected by the V3008 diagnostic.


V3008. The 'x' variable is assigned values twice successively. Perhaps this is a mistake.


SharpDevelop

V3008 The 'foundInvocations' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 211, 209. RedundantAssignmentIssue.cs 211


public override void VisitInvocationExpression(
  InvocationExpression methodDeclaration)
{
  ....
  foundInvocations = (idExpression.Identifier == _varName);
  foundInvocations = true;
  ....
}

SharpDevelop

V3008 The 'pos' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 151, 148. CodeSnippet.cs 151


public static Snippet CreateAvalonEditSnippet(
  ITextEditor context, string snippetText)
{
  ....
  int pos = 0;
  foreach (Match m in pattern.Matches(snippetText)) {
    if (pos < m.Index) {
      snippet.Elements.Add(....);
      pos = m.Index;                                  // <=
    }
    snippet.Elements.Add(CreateElementForValue(
      context, replaceableElements, m.Groups[1].Value,
      m.Index, snippetText));
    pos = m.Index + m.Length;                         // <=
  }
  ....
}

SharpDevelop

V3008 The 'd' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 121, 120. AddNewFileCommand.cs 121


object LoadResource(string name)
{
  ....
  try {
    FileStream s = new FileStream(name, FileMode.Open);
    BinaryReader r = new BinaryReader(s);
    Byte[] d = new Byte[(int)s.Length];
    d = r.ReadBytes((int)s.Length);
    s.Close();
    return d;
  } catch (Exception ex) {
  ....
}

SharpDevelop

V3008 The 'clickedNode' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 105, 104. PositionedGraphNodeControl.xaml.cs 105


void PropertyExpandButton_Click(object sender, RoutedEventArgs e)
{
  ....
  ContentPropertyNode clickedNode =
    clickedButton.DataContext as ContentPropertyNode;
  clickedNode = clickedButton.DataContext as ContentPropertyNode;
  if (clickedNode == null)
  ....
}

The code is redundant. Repeated assignment can be removed.


SharpDevelop

V3008 The 'ignoreDialogIdSelectedInTextEditor' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 204, 201. WixDialogDesigner.cs 204


void OpenDesigner()
{
  try {
    ignoreDialogIdSelectedInTextEditor = true;
    WorkbenchWindow.ActiveViewContent = this;
  } finally {
    ignoreDialogIdSelectedInTextEditor = false;
  }
}

Microsoft Code Contracts

V3008 The 'this.InsideMonitor' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 751, 749. AssertionCrawlerAnalysis.cs 751


private Data(Data state, Variable v)
{
  this.IsReached = state.IsReached;
  this.InsideMonitor = state.InsideMonitor;  // <=
  this.symbols = new List<Variable>(state.symbols) { v };
  this.InsideMonitor = false;                // <=
}

.NET Core Libraries (CoreFX)

V3008 The 'HResult' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 169, 166. WebSocketException.cs 169


private void SetErrorCodeOnError(int nativeError)
{
    if (!Succeeded(nativeError))
    {
        HResult = nativeError;
    }

    HResult = nativeError;  // <=
}

.NET Core Libraries (CoreFX)

V3008 The 'ResPrec' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 1735, 1731. SQLDecimal.cs 1735


public static SqlDecimal operator /(SqlDecimal x, SqlDecimal y)
{
  int ResPrec;
  ....
  ResPrec = ResScale + x.m_bPrec + y.m_bPrec + 1;     // <=
  MinScale = Math.Min(ResScale, s_cNumeDivScaleMin);

  ResInteger = Math.Min(ResInteger, s_NUMERIC_MAX_PRECISION);
  ResPrec = ResInteger + ResScale;                    // <=

  if (ResPrec > s_NUMERIC_MAX_PRECISION)
      ResPrec = s_NUMERIC_MAX_PRECISION;
  ....
}

.NET Core Libraries (CoreFX)

V3008 The 'prefix' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 953, 952. XmlSerializationWriter.cs 953


protected void WriteAttribute(string localName, string ns, ....)
{
  ....
  string prefix = localName.Substring(0, colon);
  prefix = _w.LookupPrefix(ns);
  _w.WriteStartAttribute(prefix,
                         localName.Substring(colon + 1), ns);
  ....
}

.NET Compiler Platform ("Roslyn")

V3008 The 'retVal' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 324, 313. DiagnosticExtensions.cs 324


public static string Stringize(this Diagnostic e)
{
  var retVal = string.Empty;
  if (e.Location.IsInSource)
  {
    retVal = e.Location.SourceSpan.ToString() + ": ";
  }
  else if (e.Location.IsInMetadata)
  {
    return "metadata: ";
  }
  else
  {
    return "no location: ";
  }
  retVal = e.Severity.ToString() + " " + e.Id + ": " +
           e.GetMessage(CultureInfo.CurrentCulture);
  return retVal;
}

.NET Compiler Platform ("Roslyn")

V3008 The 'count' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 317, 314. SymReader.cs 317


public int GetMethodsInDocument(
  ISymUnmanagedDocument document,
  int bufferLength,
  out int count,
  ....)
{
  ....
  if (bufferLength > 0)
  {
    ....
    count = actualCount;
  }
  else
  {
    count = extentsByMethod.Length;
  }
  count = 0;
  return HResult.S_OK;
}

Sony ATF

V3008 The 'Y' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 221, 217. Atf.Core.vs2010 QuatF.cs 221


public float X;
public float Y;

public float Z;
public void Set(Matrix4F m)
{
  ....
  ww = -0.5 * (m.M22 + m.M33);
  if (ww >= 0)
  {
    if (ww >= EPS2)
    {
      double wwSqrt = Math.Sqrt(ww);
      X = (float)wwSqrt;
      ww = 0.5 / wwSqrt;
      Y = (float)(m.M21 * ww);
      Z = (float)(m.M31 * ww);
      return;
    }
  }
  else
  {
    X = 0;
    Y = 0;
    Z = 1;
    return;
  }

  X = 0;
  ww = 0.5 * (1.0f - m.M33);
  if (ww >= EPS2)
  {
    double wwSqrt = Math.Sqrt(ww);
    Y = (float)wwSqrt;                   // <=
    Z = (float)(m.M32 / (2.0 * wwSqrt));
  }

  Y = 0; // <=
  Z = 1;
}

Sony ATF

V3008 The 'Z' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 222, 218. Atf.Core.vs2010 QuatF.cs 222


public float X;
public float Y;

public float Z;
public void Set(Matrix4F m)
{
  ....
  ww = -0.5 * (m.M22 + m.M33);
  if (ww >= 0)
  {
    if (ww >= EPS2)
    {
      double wwSqrt = Math.Sqrt(ww);
      X = (float)wwSqrt;
      ww = 0.5 / wwSqrt;
      Y = (float)(m.M21 * ww);
      Z = (float)(m.M31 * ww);
      return;
    }
  }
  else
  {
    X = 0;
    Y = 0;
    Z = 1;
    return;
  }

  X = 0;
  ww = 0.5 * (1.0f - m.M33);
  if (ww >= EPS2)
  {
    double wwSqrt = Math.Sqrt(ww);
    Y = (float)wwSqrt;
    Z = (float)(m.M32 / (2.0 * wwSqrt)); // <=
  }

  Y = 0;
  Z = 1; // <=
}

Samples by the Infragistics Company

V3008 The 'x' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 96, 95. RectEx.cs


public static void Normalize(....)
{
  var x = rect.X < boundingRect.X ? boundingRect.X : rect.X;
  x = (rect.X + rect.Width) > boundingRect.Right ?
      boundingRect.X : rect.X;
}

Samples by the Infragistics Company

V3008 The 'color' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 165, 163. BrushTool.cs


private static GradientStopCollection fromInterpolation(....){
  ....
  Color color=ColorTool.FromAHSV(ahsv[0],
                                 ahsv[1],
                                 ahsv[2],
                                 ahsv[3]);
  color = ColorTool.FromARGBInterpolation(min, p, max[i].Color);
  ....
}

WPF samples by Microsoft

V3008 The 'arg' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 176, 173. CommandLine.cs 176


private object InvokMethod(....)
{
  arg = commandLine.Substring(
    commandLine.IndexOf("(", StringComparison.Ordinal) + 1,
      commandLine.IndexOf(")",
        StringComparison.Ordinal) -
        (commandLine.IndexOf("(",
          StringComparison.Ordinal) + 1));
  arg = commandLine.Substring(
    commandLine.IndexOf("(",
      StringComparison.Ordinal) + 1);
}

Old NASA World Wind (C#)

V3008 The 'X' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 40, 38. Point3d.cs 40


public Point3d (Point3d P)
{
   X = P.X;
   Y = P.Y;
   X = P.Z;  // <=
}

Similar errors can be found in some other places:

  • V3008 The 'this._imagePath' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 270, 263. ImageLayer.cs 270
  • V3008 The 'm_PolygonFill' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 1623, 1618. ShapeFileLayer.cs 1623

GitExtensions

V3008 The 'exp.ExceptionPointers' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 124, 123. NBug DumpWriter.cs 124


private static bool Write(....)
{
  ....
  exp.ExceptionPointers = IntPtr.Zero;
  exp.ExceptionPointers = Marshal.GetExceptionPointers();
  ....
}

Media Portal 2

V3008 The 'Released' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 57, 56. OmDbSeasonEpisode.cs 57


public string ReleasedStr
{
  get {
    ....
  }
  set {
    DateTime releaseDate;
    if (DateTime.TryParse(value, out releaseDate))
      Released = releaseDate;
    Released = null;                        // <=
  }
}

Perhaps forgot add 'else' block for 'if' statement and put 'Released = null' into them.


PascalABC.NET

V3008 The 'codeCompileUnit' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 126, 124. VisualPascalABCNET CodeDomHostLoader.cs 126


CodeCompileUnit codeCompileUnit = null;
private DesignSurface Designer;
....
protected override CodeCompileUnit Parse()
{
  ....
  CodeCompileUnit ccu = null;
  DesignSurface ds = new DesignSurface();
  ....
  ccu = cg.GetCodeCompileUnit(idh);
  ....
  codeCompileUnit = ccu;
  Designer = ds;
  codeCompileUnit = ccu;  // <=
  ....
}

Similar errors can be found in some other places:

  • V3008 The 'mSTEPToolStripMenuItem_Enabled' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 541, 532. VisualPascalABCNET VisibilityService.cs 541
  • V3008 The variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 62, 60. NETGenerator Helpers.cs 62
  • V3008 The 'loc' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 2123, 2122. TreeConverter compilation_context.cs 2123
  • And 3 additional diagnostic messages.


Do you make errors in the code?

Check your code
with PVS-Studio

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

goto PVS-Studio;
On our website we use a cookie to collect information of a technical nature.
If you do not agree, please leave the site. Learn More →
Do not show again