I've tested the our PVS-Studio analyzer with QT project. While analyzing this project I've found some mistake. I hope, it will help to improve the project. ---------------------------------------------------------- V571 Recurring check. The 'if (endian == DetectEndianness)' condition was already verified in line 470. bootstrap qutfcodec.cpp 471 QString QUtf32::convertToUnicode(...) { ... if (endian == DetectEndianness) { if (endian == DetectEndianness) { ... } ---------------------------------------------------------- V560 A part of conditional expression is always true: 0x20000000. QtCore qcoreapplication_win.cpp 870 V560 A part of conditional expression is always true: 0x40000000. QtCore qcoreapplication_win.cpp 871 V560 A part of conditional expression is always true: 0x80000000. QtCore qcoreapplication_win.cpp 872 QString decodeMSG(const MSG& msg) { ... int repCount = (lKeyData & 0xffff); // Bit 0-15 int scanCode = (lKeyData & 0xf0000) >> 16; // Bit 16-23 bool contextCode = (lKeyData && 0x20000000); // Bit 29 bool prevState = (lKeyData && 0x40000000); // Bit 30 bool transState = (lKeyData && 0x80000000); // Bit 31 ... } ---------------------------------------------------------- V501 There are identical sub-expressions to the left and to the right of the '-' operator: orig->y1 - orig->y1 QtGui qbezier.cpp 329 static ShiftResult shift(...) { ... qreal l = (orig->x1 - orig->x2)*(orig->x1 - orig->x2) + (orig->y1 - orig->y2)*(orig->y1 - orig->y1) * (orig->x3 - orig->x4)*(orig->x3 - orig->x4) + (orig->y3 - orig->y4)*(orig->y3 - orig->y4); ... } "orig->y1 - orig->y1" ===>>>> "orig->y1 - orig->y2". ---------------------------------------------------------- V501 There are identical sub-expressions to the left and to the right of the '||' operator: iw <= 0 || iw <= 0 QtGui qfontengine_win.cpp 1103 QNativeImage *QFontEngineWin::drawGDIGlyph(...) { ... int iw = gm.width.toInt(); int ih = gm.height.toInt(); if (iw <= 0 || iw <= 0) return 0; ... } Need: if (iw <= 0 || ih <= 0) ---------------------------------------------------------- V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 230, 233. QtGui qtextcontrol.cpp 230 bool QTextControlPrivate::cursorMoveKeyEvent(QKeyEvent *e) { ... else if (e == QKeySequence::MoveToNextLine) { op = QTextCursor::Down; } else if (e == QKeySequence::MoveToPreviousLine) { op = QTextCursor::Up; } else if (e == QKeySequence::MoveToPreviousLine) { op = QTextCursor::Up; } else if (e == QKeySequence::MoveToStartOfLine) { op = QTextCursor::StartOfLine; ... } Double if: "e == QKeySequence::MoveToPreviousLine". ---------------------------------------------------------- V501 There are identical sub-expressions 'State_Sunken' to the left and to the right of the '|' operator. QtGui qwindowsstyle.cpp 1365 void QWindowsStyle::drawPrimitive(...) { ... } else if (flags & (State_Raised | State_Sunken | State_On | State_Sunken)) { ... } ---------------------------------------------------------- V523 The 'then' statement is equivalent to the 'else' statement. Qt3Support q3datetimeedit.cpp 2170 QString Q3TimeEdit::sectionFormattedText(int sec) { ... if (d->typing && sec == d->ed->focusSection()) d->ed->setSectionSelection(sec, offset - txt.length(), offset); else d->ed->setSectionSelection(sec, offset - txt.length(), offset); ... } ---------------------------------------------------------- V501 There are identical sub-expressions to the left and to the right of the '&&' operator. Qt3Support q3richtext.cpp 6978 Q3TextCustomItem* Q3TextDocument::parseTable(...) { ... while (end < length && !hasPrefix(doc, length, end, QLatin1String("m_hasGetterSetterProperties' variable is assigned to itself. QtScript structure.cpp 512 PassRefPtr Structure::getterSetterTransition(Structure* structure) { ... RefPtr transition = create(structure->storedPrototype(), structure->typeInfo()); transition->m_propertyStorageCapacity = structure->m_propertyStorageCapacity; transition->m_hasGetterSetterProperties = transition->m_hasGetterSetterProperties; transition->m_hasNonEnumerableProperties = structure->m_hasNonEnumerableProperties; transition->m_specificFunctionThrashCount = structure->m_specificFunctionThrashCount; ... } Error: transition->m_hasGetterSetterProperties = transition->m_hasGetterSetterProperties; ---------------------------------------------------------- V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 504, 508. QtMultimedia qvideosurfaceformat.cpp 504 QVariant QVideoSurfaceFormat::property(const char *name) const { if (qstrcmp(name, "handleType") == 0) { return qVariantFromValue(d->handleType); } else if (qstrcmp(name, "pixelFormat") == 0) { return qVariantFromValue(d->pixelFormat); } else if (qstrcmp(name, "handleType") == 0) { return qVariantFromValue(d->handleType); } else if (qstrcmp(name, "frameSize") == 0) { ... } Double if: "qstrcmp(name, "handleType")" ---------------------------------------------------------- V501 There are identical sub-expressions to the left and to the right of the '||' operator: ignoreTrans || ignoreTrans QtDeclarative qdeclarativestategroup.cpp 400 void QDeclarativeStateGroupPrivate::setCurrentStateInternal(...) { ... QDeclarativeTransition *transition = (ignoreTrans || ignoreTrans) ? 0 : findTransition(currentState, state); ... } ---------------------------------------------------------- V501 There are identical sub-expressions to the left and to the right of the '&&' operator. QtWebKit renderstyle.h 162 bool operator==(const InheritedFlags& other) const { ... return (_empty_cells == other._empty_cells) && (_caption_side == other._caption_side) && (_list_style_type == other._list_style_type) && (_list_style_position == other._list_style_position) && (_visibility == other._visibility) && (_text_align == other._text_align) && (_text_transform == other._text_transform) && <<<====!! (_text_decorations == other._text_decorations) && (_text_transform == other._text_transform) && <<<====!! (_cursor_style == other._cursor_style) && (_direction == other._direction) && (_border_collapse == other._border_collapse) && (_white_space == other._white_space) && (_box_direction == other._box_direction) && (_visuallyOrdered == other._visuallyOrdered) && (_htmlHacks == other._htmlHacks) && (_force_backgrounds_to_white == other._force_backgrounds_to_white) && (_pointerEvents == other._pointerEvents); ... } ---------------------------------------------------------- относится к LIBMNG V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 14670 mng_retcode mng_promote_g8_g16 (mng_datap pData) { ... mng_uint16 iW; ... *pDstline = (mng_uint8)(iW >> 8); *(pDstline+1) = (mng_uint8)(iW && 0xFF); ... } Need: *(pDstline+1) = (mng_uint8)(iW & 0xFF); And here: False 1 38757 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 14788 False False 1 38760 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 14909 False False 1 38763 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15043 False False 1 38765 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15127 False False 1 38766 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15129 False False 1 38771 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15211 False False 1 38772 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15216 False False 1 38775 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15298 False False 1 38776 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15300 False False 1 38778 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15302 False False 1 38780 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15403 False False 1 38781 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15405 False False 1 38783 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15407 False False 1 38785 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15540 False False 1 38786 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15542 False False 1 38788 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15544 False False 1 38790 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15643 False False 1 38791 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15645 False False 1 38793 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15647 False False 1 38794 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15649 False False 1 38795 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15691 False False 1 38796 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15693 False False 1 38798 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15695 False False 1 38799 V560 A part of conditional expression is always true: 0xFF. qmng libmng_pixels.c 15697 False ---------------------------------------------------------- V501 There are identical sub-expressions to the left and to the right of the '&&' operator: mt.pbFormat && mt.pbFormat phonon_ds9 videorenderer_soft.cpp 462 QSize VideoRendererSoftFilter::videoSize() const { ... if (mt.pbFormat && mt.pbFormat) { ... } Need: if (mt.pbFormat && mt.cbFormat) { ---------------------------------------------------------- V547 Expression '-- size >= 0' is always true. Unsigned type value is always >= 0. QtCLucene arrays.h 154 bool equals( class1* val1, class2* val2 ) const{ { ... size_t size = val1->size(); ... while ( --size >= 0 ){ if ( !comp(*itr1,*itr2) ) return false; itr1++; itr2++; } ... } ---------------------------------------------------------- V547 Expression 'q->getQueryName () != L"BooleanQuery"' is always true. To compare strings you should use wcscmp() function. QtCLucene multifieldqueryparser.cpp 44 Query* MultiFieldQueryParser::parse(...) { ... if (q && (q->getQueryName() != _T("BooleanQuery") ... } getQueryName возвращает указатель: const TCHAR* getQueryName() const; And here: V547 Expression 'q->getQueryName () != L"BooleanQuery"' is always true. To compare strings you should use wcscmp() function. QtCLucene multifieldqueryparser.cpp 63 ---------------------------------------------------------- V512 A call of the 'memset' function will lead to underflow of the buffer 's_attr_table'. qt3to4 cpplexer.cpp 77 int s_attr_table[256]; void CppLexer::setupScanTable() { ... memset(s_attr_table, 0, 256); ... } And here: V512 A call of the 'memset' function will lead to underflow of the buffer 's_attr_table'. qt3to4 rpplexer.cpp 60 ---------------------------------------------------------- V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 2303, 2305. lrelease profileevaluator.cpp 2303 QStringList ProFileEvaluator::Private::values(...) { ... else if (ver == QSysInfo::WV_NT) ret = QLatin1String("WinNT"); else if (ver == QSysInfo::WV_2000) ret = QLatin1String("Win2000"); else if (ver == QSysInfo::WV_2000) <<-- 2003 ret = QLatin1String("Win2003"); else if (ver == QSysInfo::WV_XP) ret = QLatin1String("WinXP"); ... } ---------------------------------------------------------- V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 340, 348. QtDesigner widgetfactory.cpp 340 QWidget *WidgetFactory::createWidget(...) { ... } else if (widgetName == m_strings.m_qDockWidget) { <<---!! w = new QDesignerDockWidget(parentWidget); } else if (widgetName == m_strings.m_qMenuBar) { w = new QDesignerMenuBar(parentWidget); } else if (widgetName == m_strings.m_qMenu) { w = new QDesignerMenu(parentWidget); } else if (widgetName == m_strings.m_spacer) { w = new Spacer(parentWidget); } else if (widgetName == m_strings.m_qDockWidget) { <<---!! w = new QDesignerDockWidget(parentWidget); ... } ---------------------------------------------------------- V519 The 'tos' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 811, 819. bootstrap qxmlstream.cpp 819 void QXmlStreamReaderPrivate::init() { tos = 0; scanDtd = false; token = -1; token_char = 0; isEmptyElement = false; isWhitespace = true; isCDATA = false; standalone = false; tos = 0; ... } ---------------------------------------------------------- V519 The 'ret' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 3765, 3767. QtGui qcleanlooksstyle.cpp 3767 int QCleanlooksStyle::pixelMetric(...) { ... case PM_SpinBoxFrameWidth: ret = 3; break; case PM_MenuBarItemSpacing: ret = 6; case PM_MenuBarHMargin: ret = 0; break; ... } Need "break;" ---------------------------------------------------------- V519 The 'x1' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 2218, 2219. Qt3Support q3canvas.cpp 2219 bool qt_testCollision(const Q3CanvasSprite* s1, const Q3CanvasSprite* s2) { ... t=x1; x1=x2; x2=t; t=y1; x1=y2; y2=t; ... } Need: t=y1; y1=y2; y2=t; ---------------------------------------------------------- V519 The 'selectable' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 646, 652. Qt3Support q3listview.cpp 652 void Q3ListViewItem::init() { ... selectable = true; lsc = Unsorted; lso = true; // unsorted in ascending order :) configured = false; expandable = false; selectable = true; ... } Double: selectable = true; ---------------------------------------------------------- V519 The 'retVal' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 169, 171. QtWebKit inspectorclientqt.cpp 171 static String variantToSetting(const QVariant& qvariant) { String retVal; switch (qvariant.type()) { case QVariant::Bool: retVal = qvariant.toBool() ? "true" : "false"; case QVariant::String: retVal = qvariant.toString(); default: break; } return retVal; } Need: break; ---------------------------------------------------------- V519 The 'shortVersion' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 1791, 1795. qdoc3 htmlgenerator.cpp 1795 void HtmlGenerator::generateHeader(...) { ... QString shortVersion; shortVersion = project + " " + shortVersion + ": "; if (node && !node->doc().location().isEmpty()) out() << "\n"; shortVersion = myTree->version(); ... } Need: shortVersion += myTree->version(); ---------------------------------------------------------- V545 Such conditional expression of 'if' operator is incorrect for the HRESULT type value '(HRESULT) 0L'. The SUCCEEDED or FAILED macro should be used instead. phonon_ds9 qbasefilter.cpp 60 STDMETHODIMP QEnumPins::QueryInterface(const IID &iid,void **out) { ... if (S_OK) AddRef(); return hr; } ----------------------------------------------------------