Примеры ошибок, обнаруженных с помощью диагностики V3004


V3004. The 'then' statement is equivalent to the 'else' statement.


Umbraco

V3004 The 'then' statement is equivalent to the 'else' statement. TinyMCE.cs 170


public TinyMCE(IData Data, string Configuration)
{
  ....
  if (p.Alias.StartsWith("."))
    styles += p.Text + "=" + p.Alias;
  else
    styles += p.Text + "=" + p.Alias;
  ....
}

SharpDevelop

V3004 The 'then' statement is equivalent to the 'else' statement. Editor.cs 225


new public bool Enabled {
  get { return base.Enabled; }
  set {
    if (this.InvokeRequired) {
      base.Enabled = this.VScrollBar.Enabled =
      this.hexView.Enabled =this.textView.Enabled =
      this.side.Enabled = this.header.Enabled = value;
    } else {
      base.Enabled = this.VScrollBar.Enabled =
      this.hexView.Enabled = this.textView.Enabled =
      this.side.Enabled = this.header.Enabled = value;
    }
  }
}

Microsoft Code Contracts

V3004 The 'then' statement is equivalent to the 'else' statement. Metadata.cs 2602


private void SerializeFieldRvaTable(....)
{
  ....
  switch (row.TargetSection){
    case PESection.SData:
    case PESection.TLS:
      Fixup fixup = new Fixup();
      fixup.fixupLocation = writer.BaseStream.Position;
      fixup.addressOfNextInstruction = row.RVA;
      if (row.TargetSection == PESection.SData){
        sdataFixup.nextFixUp = fixup;   // <=
        sdataFixup = fixup;             // <=
      }else{
        sdataFixup.nextFixUp = fixup;   // <=
        sdataFixup = fixup;             // <=
      }
      writer.Write((int)0);
      break;
  ....
}

Similar errors can be found in some other places:

  • V3004 The 'then' statement is equivalent to the 'else' statement. Nodes.cs 6698
  • V3004 The 'then' statement is equivalent to the 'else' statement. Nodes.cs 6713
  • V3004 The 'then' statement is equivalent to the 'else' statement. WarningSuggestionLinkOutput.cs 108
  • And 1 additional diagnostic messages.

.NET Core Libraries (CoreFX)

V3004 The 'then' statement is equivalent to the 'else' statement. XmlSerializationWriterILGen.cs 1213


private void WriteMember(...., TypeDesc memberTypeDesc, ....)
{
  ....
  if (memberTypeDesc.IsArray)
  {
    LocalBuilder localI = ilg.DeclareOrGetLocal(...., iVar);
    ilg.For(localI, 0, ilg.GetLocal(aVar));
  }
  else
  {
    LocalBuilder localI = ilg.DeclareOrGetLocal(...., iVar);
    ilg.For(localI, 0, ilg.GetLocal(aVar));
  }
  ....
}

.NET Core Libraries (CoreFX)

V3004 The 'then' statement is equivalent to the 'else' statement. SqlUtil.cs 93


internal static void ContinueTask(....)
{
  ....
  if (connectionToDoom != null || connectionToAbort != null)
  {
    try
    {
      onSuccess();
    }
    catch (Exception e)
    {
      completion.SetException(e);
    }
  }
  else
  { // no connection to doom - reliability section not required
    try
    {
      onSuccess();
    }
    catch (Exception e)
    {
      completion.SetException(e);
    }
  }
  ....
}

.NET Compiler Platform ("Roslyn")

V3004 The 'then' statement is equivalent to the 'else' statement. GetSemanticInfoTests.cs 2269


public void IndexerMemberRace()
{
  ....
  for (int i = 0; i < 20; i++)
  {
    ....
    if (i % 2 == 0)
    {
      thread1.Start();
      thread2.Start();
    }
    else
    {
      thread1.Start();
      thread2.Start();
    }
    ....
  }
  ....
}

Sony ATF

V3004 The 'then' statement is equivalent to the 'else' statement. Atf.Gui.WinForms.vs2010 DropDescriptionHelper.cs 199


public static void DefaultGiveFeedback(IComDataObject data,
                                       GiveFeedbackEventArgs e)
{
  ....
  if (setDefaultDropDesc &&
      (DropImageType)e.Effect != currentType)
  {
    if (e.Effect != DragDropEffects.None)
    {
      SetDropDescription(data,
        (DropImageType)e.Effect, e.Effect.ToString(), null);
    }
    else
    {
      SetDropDescription(data,
        (DropImageType)e.Effect, e.Effect.ToString(), null);
    }
    ....
  }
}

Space Engineers

V3004 The 'then' statement is equivalent to the 'else' statement. Sandbox.Game MyAgentBot.cs 260


private void StartRespawn()
{
  m_lastCountdownTime = MySandboxGame
                          .TotalGamePlayTimeInMilliseconds;
  if (m_removeAfterDeath)
    m_deathCountdownMs = AgentDefinition.RemoveTimeMs;
  else
    m_deathCountdownMs = AgentDefinition.RemoveTimeMs;
}

Space Engineers

V3004 The 'then' statement is equivalent to the 'else' statement. Sandbox.Game MyNavigationTriangle.cs 189


private static bool IsTriangleDangerous(int triIndex)
{
  if (MyPerGameSettings.NavmeshPresumesDownwardGravity)
  {
    return triIndex == -1;
  }
  else
  {
    return triIndex == -1;
  }
}

Space Engineers

V3004 The 'then' statement is equivalent to the 'else' statement. Sandbox.Game MyThrust.cs 149


public void UpdateLight()
{
  ....
  if (((MyCubeGrid)Parent).GridSizeEnum == MyCubeSize.Large)
    Light.GlareIntensity = 0.5f + length * 2;
  else
    Light.GlareIntensity = 0.5f + length * 2;
  ....
}

Mono

V3004 The 'then' statement is equivalent to the 'else' statement. System.Windows.Forms-net_4_x TextBoxTextRenderer.cs 79


public static void DrawText (....)
{
  ....
  if (showNonPrint)
    TextRenderer.DrawTextInternal (g, text, font,
      new Rectangle (new Point ((int)x, (int)y), max_size),
      color,
      TextFormatFlags.NoPadding |
      TextFormatFlags.NoPrefix, false);
  else
    TextRenderer.DrawTextInternal (g, text, font,
      new Rectangle (new Point ((int)x, (int)y), max_size),
      color,
      TextFormatFlags.NoPadding |
      TextFormatFlags.NoPrefix, false);
  ....
}

PascalABC.NET

V3004 The 'then' statement is equivalent to the 'else' statement. VisualPascalABCNET CodeCompletionWindow.cs 204


public void HandleMouseWheel(....)
{
  ....
  if (System.Windows.Forms.SystemInformation.
      MouseWheelScrollLines > 0) {
    newValue = this.vScrollBar.Value -
      (control.TextEditorProperties.MouseWheelScrollDown ? 1 :
       -1) * multiplier;
  } else {
    newValue = this.vScrollBar.Value -
      (control.TextEditorProperties.MouseWheelScrollDown ? 1 :
       -1) * multiplier;
  }
  ....
}

Similar errors can be found in some other places:

  • V3004 The 'then' statement is equivalent to the 'else' statement. NETGenerator NETGenerator.cs 439
  • V3004 The 'then' statement is equivalent to the 'else' statement. NETGenerator NETGenerator.cs 2338
  • V3004 The 'then' statement is equivalent to the 'else' statement. NETGenerator NETGenerator.cs 4062
  • And 7 additional diagnostic messages.

Infer.NET

V3004 The 'then' statement is equivalent to the 'else' statement. Runtime RegexpTreeBuilder.cs 1080


public int Compare(Pair<int, int> x, Pair<int, int> y)
{
  if (x.First < y.First)
  {
    if (x.Second >= y.Second)
    {
      return 1;
    }
    else
    {
      return 1;
    }
  }
  else if (x.First > y.First)
  {
    if (x.Second <= y.Second)
    {
      return -1;
    }
    else
    {
      return -1;
    }
  }
  ....
}

Similar errors can be found in some other places:

  • V3004 The 'then' statement is equivalent to the 'else' statement. Runtime RegexpTreeBuilder.cs 1093

FastReport

V3004 The 'then' statement is equivalent to the 'else' statement. HtmlTextRenderer.cs 2092


public override Run Split(float availableWidth, out Run secondPart)
{
  ....
  if (r.Width > availableWidth)
  {
    List<CharWithIndex> list = new List<CharWithIndex>();
    for (int i = point; i < size; i++)
      list.Add(chars[i]);
    secondPart = new RunText(renderer, word, style, list,
                             left + r.Width, charIndex);
    list.Clear();
    for (int i = 0; i < point; i++)
        list.Add(chars[i]);
    r = new RunText(renderer, word, style, list, left, charIndex);

    return r;
  }
  else
  {
    List<CharWithIndex> list = new List<CharWithIndex>();
    for (int i = point; i < size; i++)
        list.Add(chars[i]);
    secondPart = new RunText(renderer, word, style, list,
                             left + r.Width, charIndex);
    list.Clear();
    for (int i = 0; i < point; i++)
        list.Add(chars[i]);
    r = new RunText(renderer, word, style, list, left, charIndex);
    return r;
  }
  ....
}


Найденные ошибки

Проверено проектов
344
Собрано ошибок
12 970

А ты совершаешь ошибки в коде?

Проверь с помощью
PVS-Studio

Статический анализ
кода для C, C++, C#
и Java

goto PVS-Studio;