Examples of errors detected by the V556 diagnostic

V556. The values of different enum types are compared.


XUIFramework

V556 The values of different enum types are compared: enuHAlign == Center. Borne cxstatic.cpp 151


enum EHAlign { Left, Middle , Right  };
enum EVAlign { Top,  Center , Bottom };

void CxStatic::SetHAlign(EHAlign enuHAlign)
{

  ...
  if (enuHAlign == Center)
  ...
}

This is what should have been written here:: if (enuHAlign == Middle)

Identical errors can be found in some other places:

  • V556 The values of different enum types are compared: enuVAlign == Middle. Borne cxstatic.cpp 170

Clang

V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. LLVMAsmPrinter targetlowering.h 268

V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. LLVMAsmPrinter targetlowering.h 270


enum LegalizeAction {
  Legal,
  Promote,
  Expand,
  Custom
};

enum LegalizeTypeAction {
  TypeLegal,
  TypePromoteInteger,
  TypeExpandInteger,
  TypeSoftenFloat,
  TypeExpandFloat,
  TypeScalarizeVector,
  TypeSplitVector,
  TypeWidenVector
};

LegalizeTypeAction getTypeAction(LLVMContext &Context,
                                 EVT VT) const;

EVT getTypeToExpandTo(LLVMContext &Context, EVT VT) const {
  ...
  switch (getTypeAction(Context, VT)) {
  case Legal:
    return VT;
  case Expand:
  ...
}

It works because the values coincide, but that's strange.


Windows 8 Driver Samples

V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. usb.c 450


PCHAR
DbgDevicePowerString(IN WDF_POWER_DEVICE_STATE Type)
{
  ....
  case WdfPowerDeviceD0:
    return "WdfPowerDeviceD0";
  case PowerDeviceD1:
    return "WdfPowerDeviceD1";
  case WdfPowerDeviceD2:
    return "WdfPowerDeviceD2";
  ....
}

Most likely this is what should be written here: case WdfPowerDeviceD1:

Identical errors can be found in some other places:

  • V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. pcidrv.c 1707
  • V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. device.c 367
  • V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. device.c 935
  • And 3 additional diagnostic messages.

Source Engine SDK

V556 The values of different enum types are compared: Reason == PUNTED_BY_CANNON. Server (HL2) props.cpp 1520


enum PhysGunPickup_t
{
  PICKED_UP_BY_CANNON,
  PUNTED_BY_CANNON,
  PICKED_UP_BY_PLAYER, // Picked up by +USE, not physgun.
};

enum PhysGunDrop_t
{
  DROPPED_BY_PLAYER,
  THROWN_BY_PLAYER,
  DROPPED_BY_CANNON,
  LAUNCHED_BY_CANNON,
};

void CBreakableProp::OnPhysGunDrop(...., PhysGunDrop_t Reason)
{
  ....
  if( Reason == PUNTED_BY_CANNON )
  {
    PlayPuntSound();
  }
  ....
}

Unreal Engine 4

V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. onlinesubsystemtypes.h 1154

V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. onlinesubsystemtypes.h 1158

V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. onlinesubsystemtypes.h 1162

V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. onlinesubsystemtypes.h 1166

V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. onlinesubsystemtypes.h 1170


namespace EOnlineSharingReadCategory
{
  enum Type
  {
    None          = 0x00,
    Posts         = 0x01,
    Friends       = 0x02,
    Mailbox       = 0x04,
    OnlineStatus  = 0x08,
    ProfileInfo   = 0x10,
    LocationInfo  = 0x20,
    Default       = ProfileInfo|LocationInfo,
  };
}

namespace EOnlineSharingPublishingCategory
{
  enum Type {
    None          = 0x00,
    Posts         = 0x01,
    Friends       = 0x02,
    AccountAdmin  = 0x04,
    Events        = 0x08,
    Default       = None,
  };

  inline const TCHAR* ToString(
    EOnlineSharingReadCategory::Type CategoryType)
  {
    switch (CategoryType)
    {
    case None:
    {
      return TEXT("Category undefined");
    }
    case Posts:
    {
      return TEXT("Posts");
    }
    case Friends:
    {
      return TEXT("Friends");
    }
    case AccountAdmin:
    {
      return TEXT("Account Admin");
    }
    ....
  }
}

TortoiseGit

V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. fast-export.c 449


static enum {
  ABORT, VERBATIM, WARN, WARN_STRIP, STRIP
} signed_tag_mode = ABORT;

static enum {
  ERROR, DROP, REWRITE
} tag_of_filtered_mode = ERROR;

static void handle_tag(const char *name, struct tag *tag)
{
  ....
  switch(tag_of_filtered_mode) {
  case ABORT:
  ....
}

Linux Kernel

V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. libiscsi.c 3501


enum iscsi_param {
  ....
  /* passed in through bind conn using transport_fd */
  ISCSI_PARAM_CONN_PORT,
  ISCSI_PARAM_CONN_ADDRESS,
  ....
};

/* iSCSI HBA params */
enum iscsi_host_param {
  ISCSI_HOST_PARAM_HWADDRESS,
  ISCSI_HOST_PARAM_INITIATOR_NAME,
  ISCSI_HOST_PARAM_NETDEV_NAME,
  ISCSI_HOST_PARAM_IPADDRESS,                // <=
  ISCSI_HOST_PARAM_PORT_STATE,
  ISCSI_HOST_PARAM_PORT_SPEED,
  ISCSI_HOST_PARAM_MAX,
};

int iscsi_conn_get_addr_param(struct sockaddr_storage *addr,
            enum iscsi_param param, char *buf)
{
  ....
  switch (param) {
  case ISCSI_PARAM_CONN_ADDRESS:
  case ISCSI_HOST_PARAM_IPADDRESS:           // <=
  ....
  case ISCSI_PARAM_CONN_PORT:
  case ISCSI_PARAM_LOCAL_PORT:
  ....
  default:
    return -EINVAL;
  }

  return len;
}

Identical errors can be found in some other places:

  • V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. svm.c 1360
  • V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. vmx.c 2690
  • V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. request.c 2842
  • And 1 additional diagnostic messages.

OpenToonz

V556 The values of different enum types are compared: m_action != EDIT_SEGMENT. Types: Action, CursorType. controlpointeditortool.cpp 257


enum Action { NONE,
              RECT_SELECTION,
              CP_MOVEMENT,
              SEGMENT_MOVEMENT,
              IN_SPEED_MOVEMENT,
              OUT_SPEED_MOVEMENT };

enum CursorType { NORMAL,
                  ADD,
                  EDIT_SPEED,
                  EDIT_SEGMENT,
                  NO_ACTIVE };

void ControlPointEditorTool::drawMovingSegment()
{
  int beforeIndex = m_moveSegmentLimitation.first;
  int nextIndex = m_moveSegmentLimitation.second;
  if (m_action != EDIT_SEGMENT || // <=
      beforeIndex == -1 ||
      nextIndex == -1 ||
      !m_moveControlPointEditorStroke.getStroke())
    return;
  ....
}

Casablanca

V556 The values of different enum types are compared. Types: BJHandState, BJHandResult. BlackJack_Server140 table.cpp 336


enum BJHandState {
  HR_Empty, HR_BlackJack, HR_Active, HR_Held, HR_Busted
};

enum BJHandResult {
  HR_None, HR_PlayerBlackJack, HR_PlayerWin,
  HR_ComputerWin, HR_Push
};

struct BJHand
{
  ....
  BJHandState state;
  ....
};

void DealerTable::PayUp(size_t idx)
{
  ....
  if ( player.Hand.insurance > 0 &&
       Players[0].Hand.state == HR_PlayerBlackJack )
  {
    player.Balance += player.Hand.insurance*3;
  }
  ....
}

Blender

V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. outliner_tools.c 1286


typedef enum eOutlinerIdOpTypes {
    OUTLINER_IDOP_INVALID = 0,
    OUTLINER_IDOP_UNLINK,
    OUTLINER_IDOP_LOCAL,
    ....
} eOutlinerIdOpTypes;

typedef enum eOutlinerLibOpTypes {
    OL_LIB_INVALID = 0,
    OL_LIB_RENAME,
    OL_LIB_DELETE,
} eOutlinerLibOpTypes;

static int outliner_lib_operation_exec(....)
{
    ....
    eOutlinerIdOpTypes event;                //<=
    ....
    event = RNA_enum_get(op->ptr, "type");
    switch (event) {
        case OL_LIB_RENAME:                  //<=
        {
          ....
        }
        case OL_LIB_DELETE:                  //<=
        {
          ....
        }
        default:
            /* invalid - unhandled */
            break;
    }
    ....
}

Identical errors can be found in some other places:

  • V556 The values of different enum types are compared: switch(ENUM_TYPE_A) { case ENUM_TYPE_B: ... }. outliner_tools.c 1295


Do you make errors in the code?

Check your code
with PVS-Studio

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

goto PVS-Studio;