Examples of errors detected by the V768 diagnostic
V768. Variable is of enum type. It is suspicious that it is used as a variable of a Boolean-type.
LLVM/Clang
V768 The enumeration constant 'S_MOVRELS_B64' is used as a variable of a Boolean-type. gcnhazardrecognizer.cpp 75
namespace AMDGPU {
enum {
....
S_MOVRELS_B64 = 4043,
....
};
}
static bool isSMovRel(unsigned Opcode) {
return
Opcode == AMDGPU::S_MOVRELS_B32 || AMDGPU::S_MOVRELS_B64 ||
Opcode == AMDGPU::S_MOVRELD_B32 || AMDGPU::S_MOVRELD_B64;
}
Similar errors can be found in some other places:
- V768 The enumeration constant 'S_MOVRELD_B64' is used as a variable of a Boolean-type. gcnhazardrecognizer.cpp 76
MySQL
V768 The enumeration constant 'wkb_multilinestring' is used as a variable of a Boolean-type. item_geofunc.cc 1887
enum wkbType
{
wkb_invalid_type= 0,
wkb_first= 1,
wkb_point= 1,
wkb_linestring= 2,
wkb_polygon= 3,
wkb_multipoint= 4,
wkb_multilinestring= 5,
wkb_multipolygon= 6,
wkb_geometrycollection= 7,
wkb_polygon_inner_rings= 31,
wkb_last=31
};
bool append_geometry(....)
{
....
if (header.wkb_type == Geometry::wkb_multipoint)
....
else if (header.wkb_type == Geometry::wkb_multipolygon)
....
else if (Geometry::wkb_multilinestring)
....
else
DBUG_ASSERT(false);
....
}
Firebird
V768 The variable 'traScope' is of enum type. It is odd that it is used as a variable of a Boolean-type. stmtnodes.cpp 3448
namespace EDS {
....
enum TraScope {traAutonomous = 1, traCommon, traTwoPhase};
....
}
class ExecStatementNode : ....
{
....
EDS::TraScope traScope;
....
};
void ExecStatementNode::genBlr(DsqlCompilerScratch* dsqlScratch)
{
....
if (traScope)
....
....
}
SwiftShader
V768 CWE-571 The enumeration constant 'Lshr' is used as a variable of a Boolean-type. subzeroreactor.cpp 712
static Value *createArithmetic(Ice::InstArithmetic::OpKind op,
Value *lhs, Value *rhs)
{
assert(lhs->getType() == rhs->getType() ||
(llvm::isa<Ice::Constant>(rhs) &&
(op == Ice::InstArithmetic::Shl ||
Ice::InstArithmetic::Lshr ||
Ice::InstArithmetic::Ashr)));
....
}
Here is the correct version of code: assert(lhs->getType() == rhs->getType() || (llvm::isa<Ice::Constant>(rhs) && (op == Ice::InstArithmetic::Shl || op == Ice::InstArithmetic::Lshr || op == Ice::InstArithmetic::Ashr)));
Similar errors can be found in some other places:
- V768 CWE-571 The enumeration constant 'Ashr' is used as a variable of a Boolean-type. subzeroreactor.cpp 712
XNU kernel
V768 CWE-571 The expression 'new_codec = CMODE_HYB' is of enum type. It is odd that it is used as an expression of a Boolean-type. vm_compressor_algorithms.c 419
typedef enum {
CMODE_WK = 0,
CMODE_LZ4 = 1,
CMODE_HYB = 2,
VM_COMPRESSOR_DEFAULT_CODEC = 3,
CMODE_INVALID = 4
} vm_compressor_mode_t;
void vm_compressor_algorithm_init(void) {
....
assertf(((new_codec == VM_COMPRESSOR_DEFAULT_CODEC) ||
(new_codec == CMODE_WK) ||
(new_codec == CMODE_LZ4) || (new_codec = CMODE_HYB)),
"Invalid VM compression codec: %u", new_codec);
....
}
In the expression the value 2 is assigned to the variable new_codec. Because of this the condition is always true and assertf will check nothing. The value of the variable new_codec is additionally spoiled.
RT-Thread
V768 CWE-571 The enumeration constant 'PWM_CHANNEL_DUAL_EDGE' is used as a variable of a Boolean-type. lpc_pwm.c 538
void PWM_ChannelConfig(uint8_t pwmId, uint8_t PWMChannel,
uint8_t ModeOption)
{
LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
// Single edge mode
if (ModeOption == PWM_CHANNEL_SINGLE_EDGE)
{
pPwm->PCR &=
(~ PWM_PCR_PWMSELn(PWMChannel)) & PWM_PCR_BITMASK;
}
// Double edge mode
else if (PWM_CHANNEL_DUAL_EDGE)
{
pPwm->PCR |= PWM_PCR_PWMSELn(PWMChannel);
}
}
Krita
V768 The enumeration constant 'BatchMode' is used as a variable of a Boolean-type. KisMainWindow.cpp 811
bool KisMainWindow::openDocument(const QUrl &url,
OpenFlags flags)
{
if (!QFile(url.toLocalFile()).exists()) {
if (!flags && BatchMode) { // <=
QMessageBox::critical(0,
i18nc("....", "Krita"),
i18n("....", url.url()));
}
....
}
....
}
Krita
V768 The enumeration constant 'State_Active' is used as a variable of a Boolean-type. KisOpenPane.cpp 104
void paint(....) const override
{
QStyledItemDelegate::paint(painter, option, index);
if(!(option.state & (int)(QStyle::State_Active && // <=
QStyle::State_Enabled))) // <=
{
....
}
}
Android
V768 CWE-571 The enumeration constant 'CHANGE_DISPLAY_INFO' is used as a variable of a Boolean-type. InputReader.cpp 3016
enum {
....
CHANGE_DISPLAY_INFO = 1 << 2,
....
};
void RotaryEncoderInputMapper::configure(nsecs_t when,
const InputReaderConfiguration* config, uint32_t changes) {
....
if (!changes ||
(InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
....
}
Most likely this is what should be written here: if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
Qt
V768 CWE-571 The enumeration constant 'WindingFill' is used as a variable of a Boolean-type. qpainterpath.cpp 2479
enum FillRule {
OddEvenFill,
WindingFill
};
QDataStream &operator>>(QDataStream &s, QPainterPath &p)
{
....
int fillRule;
s >> fillRule;
Q_ASSERT(fillRule == Qt::OddEvenFill || Qt::WindingFill);
....
}
Doom 1
V768 [CWE-571] The enumeration constant 'commercial' is used as a variable of a Boolean-type. wi_stuff.c 588
enum
{
commercial,
....
};
void WI_drawAnimatedBack(void)
{
....
if (commercial)
return;
....
}
ROOT
V768 The enumeration constant 'kCostComplexityPruning' is used as a variable of a Boolean-type. MethodDT.cxx 283
enum EPruneMethod {kExpectedErrorPruning=0, kCostComplexityPruning, kNoPruning};
void TMVA::MethodDT::ProcessOptions()
{
....
if (fPruneStrength < 0) fAutomatic = kTRUE;
else fAutomatic = kFALSE;
if (fAutomatic && fPruneMethod==!DecisionTree::kCostComplexityPruning){
Log() << kFATAL
<< "Sorry automatic pruning strength determination is ...." << Endl;
}
....
}
Command & Conquer
V768 The enumeration constant 'WWKEY_RLS_BIT' is used as a variable of a Boolean-type. KEYBOARD.CPP 286
typedef enum {
WWKEY_SHIFT_BIT = 0x100,
WWKEY_CTRL_BIT = 0x200,
WWKEY_ALT_BIT = 0x400,
WWKEY_RLS_BIT = 0x800,
WWKEY_VK_BIT = 0x1000,
WWKEY_DBL_BIT = 0x2000,
WWKEY_BTN_BIT = 0x8000,
} WWKey_Type;
int WWKeyboardClass::To_ASCII(int key)
{
if ( key && WWKEY_RLS_BIT)
return(KN_NONE);
return(key);
}
Amnesia: The Dark Descent
V768 The enumeration constant 'eLuxEnemyMoveState_Jogging' is used as a variable of a Boolean-type. LuxEnemyMover.cpp 672
void cLuxEnemyMover::UpdateMoveAnimation(float afTimeStep)
{
....
if(prevMoveState != mMoveState)
{
....
//Backward
if(mMoveState == eLuxEnemyMoveState_Backward)
{
....
}
....
//Walking
else if(mMoveState == eLuxEnemyMoveState_Walking)
{
bool bSync = prevMoveState == eLuxEnemyMoveState_Running
|| eLuxEnemyMoveState_Jogging
? true : false;
....
}
....
}
}
Similar errors can be found in some other places:
- V768 The enumeration constant 'eLuxEnemyMoveState_Walking' is used as a variable of a Boolean-type. LuxEnemyMover.cpp 680
- V768 The enumeration constant 'eLuxEnemyMoveState_Jogging' is used as a variable of a Boolean-type. LuxEnemyMover.cpp 688