To get a trial key
fill out the form below
Team License (standard version)
Enterprise License (extended version)
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
Examples of errors detected by the V300…

Examples of errors detected by the V3008 diagnostic

April 5, 2021

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 96


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 165


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.

Unity C# reference source code

V3008 CWE-563 The 'fail' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 1633, 1632. UNetWeaver.cs 1633


class Weaver
{
  ....
  public static bool fail;
  ....
  static public bool IsValidTypeToGenerate(....)
  {
    ....
    if (....)
    {
      ....
      Weaver.fail = true;
      fail = true;
      return false;
    }
    return true;
  }
....
}

Infer.NET

V3008 The 'lowerBound' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 324, 323. Runtime GaussianOp.cs 324


public static Gaussian SampleAverageConditional(....)
{
  ....
  if (sample.Precision < 0)
  {
    precisionIsBetween = true;
    lowerBound = -1.0 / v;
    upperBound = -mean.Precision;
  }
  else if (sample.Precision < -mean.Precision)
  {
    precisionIsBetween = true;
    lowerBound = 0;
    upperBound = -mean.Precision;
  }
  else
  {
    precisionIsBetween = false;
    lowerBound = -mean.Precision;
    lowerBound = -1.0 / v;
  }
  ....
}

AWS SDK for .NET

V3008 [CWE-563] The 'this.linker.s3.region' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 116, 114. AWSSDK.DynamoDBv2.Net45 S3Link.cs 116


public string Region
{
  get
  {
    ....
  }
  set
  {
    if (String.IsNullOrEmpty(value))
    {
      this.linker.s3.region = "us-east-1";
    }
    this.linker.s3.region = value;
  }
}

.NET Core Libraries (CoreFX)

V3008 The '_streamSet' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 123, 119. MimePart.cs 123


internal void SetContent(Stream stream)
{
  if (stream == null)
  {
    throw new ArgumentNullException(nameof(stream));
  }

  if (_streamSet)
  {
    _stream.Close();
    _stream = null;     // <=
    _streamSet = false; // <=
  }

  _stream = stream;     // <=
  _streamSet = true;    // <=
  _streamUsedOnce = false;
  TransferEncoding = TransferEncoding.Base64;
}

ShareX

V3008 The 'url' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 197, 196. Seafile.cs 197


public SeafileCheckAccInfoResponse GetAccountInfo()
{
  string url = URLHelpers.FixPrefix(APIURL);
  url = URLHelpers.CombineURL(APIURL, "account/info/?format=json");
  ....
}

Similar errors can be found in some other places:

  • V3008 The 'url' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 93, 92. Seafile.cs 93
  • V3008 The 'url' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 120, 119. Seafile.cs 120

Telerik UI for UWP

V3008 The 'currentColumnLength' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 791, 785. WrapLayout.cs 791


private void OnAvailableLengthChanged(double oldValue, double newValue)
{
  ....
  if (....)
  {
    if (currentColumnLength > 0)
    {
      var paddingValue = Math.Max(0, newValue - currentColumnLength);
      this.paddingRenderInfo.Add(paddingValue);
      currentColumnLength = 0;     // <=
      slotCount++;
    }
    this.ColumnSlotsRenderInfo.Update(i, newValue);
    this.paddingRenderInfo.Add(0);
    currentColumnLength = 0;     // <=
    slotCount++;
    continue;
  }
  else
  {
    ....
  }
  ....
}

Orchard CMS

V3008 The 'content' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 197, 190. DynamicCacheTagHelper.cs 197


public override async Task ProcessAsync(....)
{
  ....
  IHtmlContent content;
  ....
  try
  {
    content = await output.GetChildContentAsync();
  }
  finally
  {
    _cacheScopeManager.ExitScope();
  }
  content = await ProcessContentAsync(output, cacheContext);
  ....
}

Emby

V3008 The 'Chapters' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 29, 28. Title.cs 29


public Title(uint titleNum)
{
    ProgramChains = new List<ProgramChain>();
    Chapters = new List<Chapter>();
    Chapters = new List<Chapter>();
    TitleNumber = titleNum;
}

OpenRA

V3008 The 'widget.Bounds.Width' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 78, 75. SpawnSelectorTooltipLogic.cs 78


public SpawnSelectorTooltipLogic(....)
{
  ....
  var textWidth = ownerFont.Measure(labelText).X;
  if (textWidth != cachedWidth)
  {
    label.Bounds.Width = textWidth;
    widget.Bounds.Width = 2 * label.Bounds.X + textWidth; // <=
  }

  widget.Bounds.Width = Math.Max(                         // <=
    teamWidth + 2 * labelMargin,
    label.Bounds.Right + labelMargin
  );
  team.Bounds.Width = widget.Bounds.Width;
  ....
}

Open XML SDK

V3008 The '_rawOuterXml' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 164, 161. OpenXmlElement.cs 164


internal string RawOuterXml
{
    get => _rawOuterXml;

    set
    {
        if (string.IsNullOrEmpty(value))
        {
            _rawOuterXml = string.Empty;
        }

        _rawOuterXml = value;
    }
}

QuantConnect Lean

V3008 The 'MaxOrders' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 244, 240. BacktestingSetupHandler.cs 244


public bool Setup(SetupHandlerParameters parameters)
{
  ....
  if (job.UserPlan == UserPlan.Free)
  {
    MaxOrders = 10000;
  }
  else
  {
    MaxOrders = int.MaxValue;
    MaximumRuntime += MaximumRuntime;
  }

  MaxOrders = job.Controls.BacktestingMaxOrders; // <=
  ....
}

Similar errors can be found in some other places:

  • V3008 The 'SessionId' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 182, 172. BacktestResultPacket.cs 182

ONLYOFFICE Community Server

V3008 The 'key' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 244, 240. Metadata.cs 244


private byte[] GenerateKey()
{
    var key = new byte[keyLength];

    using (var deriveBytes = new Rfc2898DeriveBytes(Password, Salt, ....))
    {
        key = deriveBytes.GetBytes(keyLength);
    }

    return key;
}

C#5 -> C#8

Similar errors can be found in some other places:

  • V3008 The 'hmacKey' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 256, 252. Metadata.cs 256
  • V3008 The 'hmacHash' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 270, 264. Metadata.cs 270
  • V3008 The 'paths' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 512, 508. RackspaceCloudStorage.cs 512
  • And 2 additional diagnostic messages.

Popular related articles
The Ultimate Question of Programming, Refactoring, and Everything

Date: 04.14.2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…
The way static analyzers fight against false positives, and why they do it

Date: 03.20.2017

Author: Andrey Karpov

In my previous article I wrote that I don't like the approach of evaluating the efficiency of static analyzers with the help of synthetic tests. In that article, I give the example of a code fragment…
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: 10.22.2018

Author: Andrey Karpov

Just like other static analyzers, PVS-Studio often produces false positives. What you are about to read is a short story where I'll tell you how PVS-Studio proved, just one more time, to be more atte…
Free PVS-Studio for those who develops open source projects

Date: 12.22.2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
PVS-Studio ROI

Date: 01.30.2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…
The Evil within the Comparison Functions

Date: 05.19.2017

Author: Andrey Karpov

Perhaps, readers remember my article titled "Last line effect". It describes a pattern I've once noticed: in most cases programmers make an error in the last line of similar text blocks. Now I want t…
Static analysis as part of the development process in Unreal Engine

Date: 06.27.2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…
PVS-Studio for Java

Date: 01.17.2019

Author: Andrey Karpov

In the seventh version of the PVS-Studio static analyzer, we added support of the Java language. It's time for a brief story of how we've started making support of the Java language, how far we've co…
The Last Line Effect

Date: 05.31.2014

Author: Andrey Karpov

I have studied many errors caused by the use of the Copy-Paste method, and can assure you that programmers most often tend to make mistakes in the last fragment of a homogeneous code block. I have ne…
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: 07.31.2017

Author: Andrey Karpov

After I wrote quite a big article about the analysis of the Tizen OS code, I received a large number of questions concerning the percentage of false positives and the density of errors (how many erro…

Comments (0)

Next comments

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →
Accept