ç§ãã¡ã®ããŒã ã¯æã ããã§ã«èšäºãæžãããããžã§ã¯ããå確èªããŸãã ãã®ãããªåãã§ãã¯ãããå¥ã®ãããžã§ã¯ãã¯Qtã§ããã ååã2014幎ã«PVS-Studioã§ãã¹ãããŸããã 2014幎以æ¥ããããžã§ã¯ãã¯Coverityã®å©ããåããŠå®æçã«ãã§ãã¯ããå§ããŸããã ããã¯é¢çœãã§ãã PVS-Studioã䜿çšããŠèå³æ·±ããšã©ãŒãèŠã€ãããããã©ããã確èªããŸãããã
Qt
åã®èšäºïŒ
- ã ã³ãŒãäœæã®æ®µéã§ãšã©ãŒã®å¯èœæ§ãæžããæ¹æ³ ã ã 2011幎7æã
- ã Qt 5ãã¬ãŒã ã¯ãŒã¯ãã§ã㯠ãã2014幎4æã
ä»åã¯Qt Base ïŒã³ã¢ãGuiããŠã£ãžã§ããããããã¯ãŒã¯ãªã©ïŒãšQt5ã¹ãŒããŒã¢ãžã¥ãŒã«ããã¹ããããŸãã ã Qt Creatorã«ã€ããŠã¯ãåŸã§å¥ã®èšäºãæžãäºå®ã§ãã æ€èšŒã®ããã«ãPVS-Studioéçã¢ãã©ã€ã¶ãŒã䜿çšããŸããããã®ã¢ãã©ã€ã¶ãŒã®è©Šçšçã¯ããµã€ãããããŠã³ããŒãã§ããŸã ã
ç§ã®äž»èŠ³çãªæèŠã§ã¯ãQtã³ãŒãã¯æ¹åãããŸããã ååã®ãã¹ã以æ¥ãPVS-Studioã¢ãã©ã€ã¶ãŒã«ã¯å€ãã®æ°ãã蚺æãç»å ŽããŠããŸãã ããã«ãããããããèŠåã®ã¬ãã¥ãŒèª¿æ»äžã«ããã®ãµã€ãºã®ãããžã§ã¯ãã§ããã»ã©å€ãã®ãšã©ãŒã¯èŠã€ãããŸããã§ããã ãããç§ã®å人çãªå°è±¡ã§ããããšãããäžåºŠç¹°ãè¿ããŸãã ç§ã¯åœæãçŸåšãããšã©ãŒã®å¯åºŠã«ã€ããŠç¹å¥ãªç 究ãããŸããã§ããã
æãå¯èœæ§ãé«ãã®ã¯ãCoverityéçã¢ãã©ã€ã¶ãŒã䜿çšããå®æçãªãã§ãã¯ããããããã³ãŒãã®å質ã«åœ±é¿ããããšã§ãã 2014幎ãCoverityã®æ¯æŽã«ãããQtãããžã§ã¯ãïŒ qt-project ïŒã®ãã§ãã¯ãéå§ããã2016幎ã«ã¯Qt CreatorïŒ qt-creator ïŒã®ãã§ãã¯ãéå§ãããŸããã ç§ã®æèŠïŒãªãŒãã³ãœãŒã¹ãããžã§ã¯ããéçºããŠããå Žåã Coverity Scanã¯ãããžã§ã¯ãã®å質ãšä¿¡é Œæ§ãå€§å¹ ã«åäžãããåªããç¡æãœãªã¥ãŒã·ã§ã³ã«ãªããŸãã
ãã ããèªè ãæšæž¬ã§ããããã«ãPVS-Studioã¬ããŒãã§èå³æ·±ãããšã«æ°ä»ããªãã£ãå Žåãèšäºã¯ãããŸããã§ãã:)ã ãããŠãèšäºãã€ãŸãæ¬ é¥ãããããã§ãã ããããèŠãŠã¿ãŸãããã åèšã§ã96åã®ãšã©ãŒãæžããŸããã
ã³ããŒããŒã¹ããšã¿ã€ããã¹ã®å€±æ
ééãã®åå ãäžæ³šæã§ãããšãããžã£ã³ã«ã®å€å žããå§ããŸãããã ãããã®ãšã©ãŒã¯ããã°ã©ããŒã«ãã£ãŠéå°è©äŸ¡ãããŠããŸãã ãŸã èªãã§ããªã人ã«ã¯ã次ã®2ã€ã®èšäºãã芧ã«ãªãããšããå§ãããŸãã
ãããã®ãšã©ãŒã¯èšèªéã§ãã ããšãã°ã2çªç®ã®èšäºã§ã¯ãCãC ++ãããã³CïŒã§èšè¿°ãããæ¯èŒé¢æ°ã®ãšã©ãŒã®äŸãå€æ°çŽ¹ä»ããŠããŸãã çŸåšãPVS-Studioã§JavaèšèªãµããŒããå®è£ ãããšãåããšã©ãŒãã¿ãŒã³ãçºçããŸãã ããšãã°ã Hibernateã©ã€ãã©ãªã§æè¿èŠã€ãã£ããšã©ãŒã¯æ¬¡ã®ãšããã§ãã
public boolean equals(Object other) { if (other instanceof Id) { Id that = (Id) other; return purchaseSequence.equals(this.purchaseSequence) && that.purchaseNumber == this.purchaseNumber; } else { return false; } }
ããèŠããšã purchaseSequenceãã£ãŒã«ããããèªäœãšæ¯èŒãããŠããããšãããããŸãã æ£ãããªãã·ã§ã³ïŒ
return that.purchaseSequence.equals(this.purchaseSequence) && that.purchaseNumber == this.purchaseNumber;
äžè¬çã«ããã¹ãŠããã€ãéãã§ãããPVS-Studioã¢ãã©ã€ã¶ãŒã¯Javaãããžã§ã¯ãã§ãAugeanã®stableèãããéãããå¿ èŠããããŸãã ãšããã§ãPVS-Studio for Javaã®ããŒã¿çã®ãã¹ãã«åå ããããã«çãæåŸ ããŸããããã¯è¿ãå°æ¥ç»å Žããäºå®ã§ãã ãããè¡ãã«ã¯ã ç§ãã¡ã«æžããŠãã ãã ïŒãJavaçšã®ã¢ãã©ã€ã¶ãŒã欲ããããéžæããŠãã ãã ïŒã
Qtãããžã§ã¯ãã®ãšã©ãŒã«æ»ããŸãããã
æ¬ é¥N1
static inline int windowDpiAwareness(HWND hwnd) { return QWindowsContext::user32dll.getWindowDpiAwarenessContext && QWindowsContext::user32dll.getWindowDpiAwarenessContext ? QWindowsContext::user32dll.getAwarenessFromDpiAwarenessContext( QWindowsContext::user32dll.getWindowDpiAwarenessContext(hwnd)) : -1; }
PVS-StudioèŠåïŒV501 CWE-571ã&&ãæŒç®åã®å·Šå³ã«ã¯ãåäžã®å¯æ¬¡åŒãQWindowsContext :: user32dll.getWindowDpiAwarenessContextãããããŸãã qwindowscontext.cpp 150
ã¢ãã©ã€ã¶ãŒã¡ãã»ãŒãžã«å ããŠãããã§ã¯ç¹å¥ãªèª¬æã¯å¿ èŠãããŸããã ãã®è¡šçŸã¯æ¬¡ã®ããã«ãªã£ãŠããã¯ãã§ãã
return QWindowsContext::user32dll.getAwarenessFromDpiAwarenessContext && QWindowsContext::user32dll.getWindowDpiAwarenessContext ? QWindowsContext::user32dll.getAwarenessFromDpiAwarenessContext( QWindowsContext::user32dll.getWindowDpiAwarenessContext(hwnd)) : -1;
æ¬ é¥N2ãN3
void QReadWriteLockPrivate::release() { Q_ASSERT(!recursive); Q_ASSERT(!waitingReaders && !waitingReaders && !readerCount && !writerCount); freelist->release(id); }
PVS-StudioèŠåïŒV501 CWE-571 '&&'æŒç®åã®å·Šå³ã«åãå¯æ¬¡åŒããããŸãïŒïŒWaitingReaders &&ïŒWaitingReaders qreadwritelock.cpp 632
ãšã©ãŒã¯Q_ASSERTãã¯ãæ¡ä»¶å ã«ãããããéèŠã§ã¯ãããŸããã ããã§ããããã¯ééãã§ãã waitingReaderså€æ°ã¯äºéãã§ãã¯ãããŸãã ãããŠæããã«ã圌ãã¯ä»ã®å€æ°ããã§ãã¯ããã®ãå¿ããŠããŸããã
åããšã©ãŒãqreadwritelock.cppãã¡ã€ã«ã®625è¡ã«ãããŸãã é·æã«ãããã³ããŒããŒã¹ãïŒ :)
æ¬ é¥N4
QString QGraphicsSceneBspTree::debug(int index) const { .... if (node->type == Node::Horizontal) { tmp += debug(firstChildIndex(index)); tmp += debug(firstChildIndex(index) + 1); } else { tmp += debug(firstChildIndex(index)); tmp += debug(firstChildIndex(index) + 1); } .... }
PVS-StudioèŠåïŒV523 CWE-691ãthenãã¹ããŒãã¡ã³ãã¯ãelseãã¹ããŒãã¡ã³ããšåçã§ãã qgraphicsscene_bsp.cpp 179
ã»ãšãã©ã®å Žåãããã¹ãã®ãããã¯ãã³ããŒãããŸããããä¿®æ£ãå¿ããŠããŸããã
æ¬ é¥N5
enum FillRule { OddEvenFill, WindingFill }; QDataStream &operator>>(QDataStream &s, QPainterPath &p) { .... int fillRule; s >> fillRule; Q_ASSERT(fillRule == Qt::OddEvenFill || Qt::WindingFill); .... }
PVS-StudioèŠåïŒV768 CWE-571åæå®æ°ãWindingFillãã¯ãããŒã«åã®å€æ°ãšããŠäœ¿çšãããŸãã qpainterpath.cpp 2479
åæããŠãããã¯çŸãããã«ãŒããŒã§ãïŒ æ¡ä»¶ã¯åžžã«çã§ããããã Q_ASSERTã¯äœããã§ãã¯ããŸããã ååä»ãå®æ°Qt :: WindingFillã1ã§ãããããæ¡ä»¶ã¯çã§ãã
æ¬ é¥N6
bool QVariant::canConvert(int targetTypeId) const { .... if (currentType == QMetaType::SChar || currentType == QMetaType::Char) currentType = QMetaType::UInt; if (targetTypeId == QMetaType::SChar || currentType == QMetaType::Char) targetTypeId = QMetaType::UInt; .... }
èŠåãèªãåã«ãèªåã§ã¿ã€ããã¹ãèŠã€ããŠãã ããã åçãè¿œå ããããšã§ãã¢ãã©ã€ã¶ãŒã®ã¡ãã»ãŒãžãããã«èªãŸãªãããã«ãæäŒãããŸã:)ã
PVS-StudioèŠåïŒV560 CWE-570æ¡ä»¶åŒã®äžéšã¯åžžã«falseã§ãïŒcurrentType == QMetaType :: Charã qvariant.cpp 3529
æ¡ä»¶ãcurrentType == QMetaType :: Charãã¯ãæåã®ifã§ãã§ãã¯ãããŸãã æ¡ä»¶ãæºãããããšãå€æ°currentType㯠QMetaType :: UIntã« èšå®ãããŸãã ãããã£ãŠãããã«å€æ°currentTypeãQMetaType :: Charãšçããããããšã¯ã§ããªããªããŸãã ãããã£ãŠãã¢ãã©ã€ã¶ãŒã¯ã2çªç®ã®ifã®éšååŒãcurrentType == QMetaType :: Charããåžžã«falseã§ããããšãå ±åããŸãã
å®éã2çªç®ã®ifã¯æ¬¡ã®ããã«ãªããŸãã
if (targetTypeId == QMetaType::SChar || targetTypeId == QMetaType::Char) targetTypeId = QMetaType::UInt;
V560蚺æããŒã
ã¬ããŒãã§ã¯ãå€ãã®V560èŠåãèŠã€ãããŸããã ãã ããäžèšã®æ¬ é¥N6ãšèŠãªãããèšäºã®èå³æ·±ãäºäŸãèŠã€ããé端ãããããããèŠãŸããã§ããã
ã¡ãã»ãŒãžV560ã®å€§éšåã¯åœãšåŒã¶ããšã¯ã§ããŸãããããããããã®äœ¿çšã¯ãããŸããã èšãæããã°ãèšäºã§ãããã説æããããšã¯é¢çœããããŸããã ç§ãæ£ç¢ºã«äœãæå³ããã®ããæ確ã«ããããã«ããã®ãããªã±ãŒã¹ãæ€èšããŸãã
QString QTextHtmlExporter::findUrlForImage(const QTextDocument *doc, ....) { QString url; if (!doc) return url; if (QTextDocument *parent = qobject_cast<QTextDocument *>(doc->parent())) return findUrlForImage(parent, cacheKey, isPixmap); if (doc && doc->docHandle()) { // <= .... }
èŠåPVS-StuidioïŒV560 CWE-571æ¡ä»¶åŒã®äžéšã¯åžžã«çã§ãïŒdocã qtextdocument.cpp 2992
ã¢ãã©ã€ã¶ãŒã¯ãåãã§ãã¯æã«ããã¥ã¡ã³ããã€ã³ã¿ãŒãåžžã«nullptrã§ãªãããšã¯ééããããŸããã ããããããã¯ééãã§ã¯ãªããããã°ã©ããŒã ããå®å šã§ããã 次ã®ããã«èšè¿°ããããšã§ãã³ãŒããç°¡çŽ åã§ããŸãã
if (doc->docHandle()) {
æ¬ é¥N7
æåŸã®ã±ãŒã¹ã¯ãã¿ã€ããã¹ãšããŠåé¡ã§ããŸãã ãã®ãšã©ãŒã¯ãæåã®æåã®å Žåã®ã¿ç°ãªãå®æ°ã®ååã®æ··ä¹±ã«ããçºçããŸãã
class QWindowsCursor : public QPlatformCursor { public: enum CursorState { CursorShowing, CursorHidden, CursorSuppressed }; .... } QWindowsCursor::CursorState QWindowsCursor::cursorState() { enum { cursorShowing = 0x1, cursorSuppressed = 0x2 }; CURSORINFO cursorInfo; cursorInfo.cbSize = sizeof(CURSORINFO); if (GetCursorInfo(&cursorInfo)) { if (cursorInfo.flags & CursorShowing) .... }
PVS-StudioèŠåïŒV616 CWE-480å€ã0ã®ãCursorShowingããšããååã®å®æ°ã¯ããããåäœã®æäœã§äœ¿çšãããŸãã qwindowscursor.cpp 669
ãã詳现ã«ã¯ãå¥ã®å°ããªã¡ã¢ã§ãã®ãšã©ãŒãåæããŸããïŒã ããäžåºŠãPVS-Studioã¢ãã©ã€ã¶ãŒã¯äººããã泚ææ·±ãããšãå€æããŸãã ãã
ã»ãã¥ãªãã£ã®æ¬ é¥
å®éããã®èšäºã§èª¬æãããŠãããã¹ãŠã®ãšã©ãŒã¯ãã»ãã¥ãªãã£äžã®æ¬ é¥ãšåŒã°ããå¯èœæ§ããããŸãã ãããã¯ãã¹ãŠã Common Weakness Enumerationã«åŸã£ãŠåé¡ãããŸã ïŒã¢ãã©ã€ã¶ãŒã¡ãã»ãŒãžã®CWE IDãåç §ïŒã ãšã©ãŒãCWEãšããŠåé¡ãããå Žåãæœåšçã«ã»ãã¥ãªãã£ãªã¹ã¯ã§ãã ããã«ã€ããŠã¯ã PVS-Studio SASTããŒãžã§è©³ãã説æããŠããŸã ã
ãã ããããã€ãã®ééããå¥ã®ã°ã«ãŒãã«ãŸãšããããšæããŸãã ããããèŠãŠã¿ãŸãããã
æ¬ é¥N8ãN9
bool QLocalServerPrivate::addListener() { .... SetSecurityDescriptorOwner(pSD.data(), pTokenUser->User.Sid, FALSE); SetSecurityDescriptorGroup(pSD.data(), pTokenGroup->PrimaryGroup, FALSE); .... }
PVS-Studioã®èŠåïŒ
- V530 CWE-252é¢æ°ãSetSecurityDescriptorOwnerãã®æ»ãå€ã䜿çšããå¿ èŠããããŸãã qlocalserver_win.cpp 167
- V530 CWE-252é¢æ°ãSetSecurityDescriptorGroupãã®æ»ãå€ã䜿çšããå¿ èŠããããŸãã qlocalserver_win.cpp 168
ã¢ã¯ã»ã¹å¶åŸ¡ã«é¢é£ããããŸããŸãªæ©èœããããŸãã SetSecurityDescriptorOwneré¢æ°ãšSetSecurityDescriptorGroupé¢æ°ã¯ãã®äžã«ãããŸãã
ãã®ãããªæ©èœã䜿çšããå Žåã¯ãæ éã«äœæ¥ããå¿ èŠããããŸãã ããšãã°ãè¿ãããã¹ããŒã¿ã¹ãå¿ ã確èªããå¿ èŠããããŸãã ãããã®é¢æ°ã®åŒã³åºãã倱æãããšã©ããªããŸããïŒ æšæž¬ã¯å¿ èŠãããŸããããã®å ŽåãåŠçããã³ãŒããèšè¿°ããå¿ èŠããããŸãã
æ€èšŒã®æ¬ åŠãå©çšããŠããã®ãããªãšã©ãŒãè匱æ§ã«å€ããå¿ èŠã¯ãããŸããã ãã ããããã¯ãããã«ããŠããªã¹ã¯ã®å Žæã§ã¯ãªããããããå®å šãªã³ãŒããèšè¿°ããå¿ èŠããããŸãã
æ¬ é¥N10
bool QLocalServerPrivate::addListener() { .... InitializeAcl(acl, aclSize, ACL_REVISION_DS); .... }
PVS-StudioèŠåïŒV530 CWE-252é¢æ°ãInitializeAclãã®æ»ãå€ã䜿çšããå¿ èŠããããŸãã qlocalserver_win.cpp 144
ãã®ç¶æ³ã¯ãäžèšã§èª¬æããç¶æ³ãšäŒŒãŠããŸãã
æ¬ é¥N11ãNââ12
static inline void sha1ProcessChunk(....) { .... quint8 chunkBuffer[64]; .... #ifdef SHA1_WIPE_VARIABLES .... memset(chunkBuffer, 0, 64); #endif }
PVS-StudioèŠåïŒV597 CWE-14ã³ã³ãã€ã©ã¯ããmemsetãé¢æ°åŒã³åºããåé€ã§ããŸããããã¯ããchunkBufferããããã¡ãŒã®ãã©ãã·ã¥ã«äœ¿çšãããŸãã RtlSecureZeroMemoryïŒïŒé¢æ°ã䜿çšããŠããã©ã€ããŒãããŒã¿ãæ¶å»ããå¿ èŠããããŸãã sha1.cpp 189
ã³ã³ãã€ã©ãŒã¯ã memseté¢æ°åŒã³åºããåé€ããŸãã ãã§ã«äœåºŠãèšäºã§ãã®ç¶æ³ãåæããŸããã ç¹°ãè¿ããããããŸãã ã ãã©ã€ããŒãããŒã¿ã®å®å šãªã¯ãªãŒãã³ã° ããšããèšäºãåç §ããŸãã
ãŸããåãsha1.cppãã¡ã€ã«ã®247è¡ç®ã«å¥ã®ãšã©ãŒããããŸãã
ãã«ãã€ã³ã¿ãŒ
ãã€ã³ã¿ã«ã€ããŠè©±ãæãæ¥ãŸããã ãã®ãããã¯ã«ã¯å€ãã®ééãããããŸããã
æ¬ é¥N13
QByteArray &QByteArray::append(const char *str, int len) { if (len < 0) len = qstrlen(str); if (str && len) { .... }
PVS-StudioèŠåïŒV595 CWE-476 nullptrã«å¯ŸããŠæ€èšŒãããåã«ã 'str'ãã€ã³ã¿ãŒã䜿çšãããŸããã è¡ã確èªããŠãã ããïŒ2118ã2119ãqbytearray.cpp 2118
å€å žçãªç¶æ³ã¯ãæåã«ãã€ã³ã¿ãŒã䜿çšããã nullptrã®åçæ§ããã§ãã¯ãããå Žåã§ãã ããã¯éåžžã«äžè¬çãªãšã©ãŒãã¿ãŒã³ã§ãããã»ãŒãã¹ãŠã®ãããžã§ã¯ãã§å®æçã«èŠãããŸãã
æ¬ é¥N14ãN15
static inline const QMetaObjectPrivate *priv(const uint* data) { return reinterpret_cast<const QMetaObjectPrivate*>(data); } bool QMetaEnum::isFlag() const { const int offset = priv(mobj->d.data)->revision >= 8 ? 2 : 1; return mobj && mobj->d.data[handle + offset] & EnumIsFlag; }
PVS-StudioèŠåïŒV595 CWE-476 nullptrã«å¯ŸããŠæ€èšŒãããåã«ã 'mobj'ãã€ã³ã¿ãŒã䜿çšãããŸããã è¡ã確èªããŠãã ããïŒ2671ã2672ãqmetaobject.cpp 2671
念ã®ããã privé¢æ°ã®æ¬äœãæã¡èŸŒã¿ãŸãã äœããã®çç±ã§ãã³ãŒããæ©èœããç¶æ³ãèªè ãæãã€ãããšããããŸãã ç§ã¯ãã®äžä¿¡ãã©ãããæ¥ãã®ãããããŠããªãããŒãªæ©èœã誀ã£ãŠèŠãããšããé¡æãç解ããŠããŸãã:)ã äŸãã°ã誰ããprivã次ã®åœ¢åŒã®ãã¯ãã§ããããšãã³ã¡ã³ãã§ææ¡ãããããããŸããïŒ
#define priv(A) foo(sizeof(A))
ãã®åŸããã¹ãŠãåäœããŸãã
ãã®ãããªè°è«ãé¿ããããã«ããšã©ãŒã®ååšã確èªãããã¹ãŠã®æ å ±ãæäŸãããŠããã³ãŒãã®æçãåŒçšããããšããŸãã
ãã®ããã modjãã€ã³ã¿ãŒã¯éåç §ãããŠãããã§ãã¯ãããŸãã
ããã«ã·ãŒã³ã«ã¯ãã匷åã§æããããã³ããŒããŒã¹ãããããŸãã isScopedé¢æ°ã§ãŸã£ããåããšã©ãŒãæ€åºããããã ïŒ
bool QMetaEnum::isScoped() const { const int offset = priv(mobj->d.data)->revision >= 8 ? 2 : 1; return mobj && mobj->d.data[handle + offset] & EnumIsScoped; }
PVS-StudioèŠåïŒV595 CWE-476 nullptrã«å¯ŸããŠæ€èšŒãããåã«ã 'mobj'ãã€ã³ã¿ãŒã䜿çšãããŸããã è¡ã確èªããŠãã ããïŒ2683ã2684ãqmetaobject.cpp 2683
æ¬ é¥N16-N21
å¥ã®äŸãèããŠã¿ããšãååã ãšæããŸãã
void QTextCursor::insertFragment(const QTextDocumentFragment &fragment) { if (!d || !d->priv || fragment.isEmpty()) return; d->priv->beginEditBlock(); d->remove(); fragment.d->insert(*this); d->priv->endEditBlock(); if (fragment.d && fragment.d->doc) d->priv->mergeCachedResources(fragment.d->doc->docHandle()); }
PVS-StudioèŠåïŒV595 CWE-476 nullptrã«å¯ŸããŠæ€èšŒãããåã«ã 'fragment.d'ãã€ã³ã¿ãŒã䜿çšãããŸããã è¡ã確èªããŠãã ããïŒ2238ã2241ãqtextcursor.cpp 2238
ãã¹ãŠåãã§ãã å€æ°fragment.dã«æ ŒçŽããããã€ã³ã¿ãŒã䜿çšããäœæ¥ã®ã·ãŒã±ã³ã¹ã«æ³šæããŠãã ããã
ãã®ã¿ã€ãã®ä»ã®ãšã©ãŒïŒ
- V595 CWE-476 nullptrã«å¯ŸããŠæ€èšŒãããåã«ãããŠã£ã³ããŠããã€ã³ã¿ãŒã䜿çšãããŸããã è¡ã確èªããŠãã ããïŒ1846ã1848ãqapplication.cpp 1846
- V595 CWE-476 nullptrã«å¯ŸããŠæ€èšŒãããåã«ãããŠã£ã³ããŠããã€ã³ã¿ãŒã䜿çšãããŸããã è¡ã確èªããŠãã ããïŒ1858ã1860ãqapplication.cpp 1858
- V595 CWE-476 nullptrã«å¯ŸããŠæ€èšŒãããåã«ããå¿çããã€ã³ã¿ãŒã䜿çšãããŸããã è¡ã確èªããŸãïŒ492ã502ãqhttpnetworkconnectionchannel.cpp 492
- V595 CWE-476 nullptrã«å¯ŸããŠæ€èšŒãããåã«ããnewHandleããã€ã³ã¿ãŒã䜿çšãããŸããã è¡ã確èªããŠãã ããïŒ877ã883ãqsplitter.cpp 877
- V595 CWE-476 nullptrã«å¯ŸããŠæ€èšŒãããåã«ãããŠã£ãžã§ããããã€ã³ã¿ãŒã䜿çšãããŸããã è¡ã確èªããŠãã ããïŒ2320ã2322ãqwindowsvistastyle.cpp 2320
- å®éãããã«ãšã©ãŒããããŸãã ç§ã¯ããã«V595ã®èŠåãåŠç¿ããããšã«ãããããããã®èšäºã®ããã«ãã§ã«ååãªã³ãŒãã¹ãããããæžããŸããã
æ¬ é¥N22-N33
ãã€ã³ã¿ãŒããã§ãã¯ããã newæŒç®åãè¿ãã³ãŒãããããŸãã ããã¯ã mallocé¢æ°ã®çµæããã§ãã¯ãããªãå Žæããããããããšããäºå®ã®äžã§ç¹ã«é¢çœããã®ã§ãïŒæ¬¡ã®ãšã©ãŒã°ã«ãŒããåç §ïŒã
bool QTranslatorPrivate::do_load(const QString &realname, const QString &directory) { .... d->unmapPointer = new char[d->unmapLength]; if (d->unmapPointer) { file.seek(0); qint64 readResult = file.read(d->unmapPointer, d->unmapLength); if (readResult == qint64(unmapLength)) ok = true; } .... }
PVS-StudioèŠåïŒV668 CWE-571ãnewãæŒç®åã䜿çšããŠã¡ã¢ãªãå²ãåœãŠãããããããd-> unmap Pointerããã€ã³ã¿ãnullã«å¯ŸããŠãã¹ãããŠãæå³ããããŸããã ã¡ã¢ãªå²ãåœãŠãšã©ãŒã®å ŽåãäŸå€ãçæãããŸãã qtranslator.cpp 596
ã¡ã¢ãªå²ãåœãŠãšã©ãŒã®å ŽåãäŸå€std :: bad_allocãã¹ããŒãããããããã€ã³ã¿ãŒã®ãã§ãã¯ã¯æå³ããããŸããã ååãªã¡ã¢ãªããªããšãã«newptrãnullptrãè¿ãããã«ããã«ã¯ã次ã®ããã«èšè¿°ããå¿ èŠããããŸãã
d->unmapPointer = new (std::nothrow) char[d->unmapLength];
ã¢ãã©ã€ã¶ãŒã¯ããã®æ°ããæŒç®åã®äœ¿çšäºäŸãèªèããŠããããã®å ŽåèŠåãçºããŸããã
ãã®ä»ã®ãšã©ãŒïŒ qt-V668.txtãã¡ã€ã«ãæäŸããŸã ã
æ¬ é¥N34-N70
çŽæã©ãããé¢æ°malloc ã calloc ã strdupãªã©ã®åŒã³åºãã®çµæããã§ãã¯ããªãå Žåããšã©ãŒãçºçããŸãã ãããã®ãšã©ãŒã¯ãäžèŠæããããããæ·±å»ã§ãã 詳现ïŒã mallocé¢æ°ãäœãè¿ãããã確èªããããšãéèŠãªã®ã¯ãªãã§ãã ãã
SourceFiles::SourceFiles() { nodes = (SourceFileNode**)malloc(sizeof(SourceFileNode*)*(num_nodes=3037)); for(int n = 0; n < num_nodes; n++) nodes[n] = nullptr; }
PVS-StudioèŠåïŒV522 CWE-690æœåšçãªãã«ãã€ã³ã¿ãŒãããŒããã®éåç §ãååšããå¯èœæ§ããããŸãã è¡ã確èªããŠãã ããïŒ138ã136ãmakefiledeps.cpp 138
ãã€ã³ã¿ãŒã¯äºåã®æ€èšŒãªãã§äœ¿çšãããŸãã
ãããã®ãšã©ãŒã¯ãã¹ãŠåãã¿ã€ãã§ããããããã以äžè©³ããã¯èª¬æããŸããã æ®ãã®èŠåãªã¹ãqt-V522-V575.txtãæäŸããŸãã
æ¡ä»¶ã®è«çãšã©ãŒ
æ¬ é¥N71
QString QEdidParser::parseEdidString(const quint8 *data) { QByteArray buffer(reinterpret_cast<const char *>(data), 13); // Erase carriage return and line feed buffer = buffer.replace('\r', '\0').replace('\n', '\0'); // Replace non-printable characters with dash for (int i = 0; i < buffer.count(); ++i) { if (buffer[i] < '\040' && buffer[i] > '\176') buffer[i] = '-'; } return QString::fromLatin1(buffer.trimmed()); }
PVS-StudioèŠåïŒV547 CWE-570åŒ 'buffer [i] <' \ 040 '&& buffer [i]>' \ 176 ''ã¯åžžã«falseã§ãã qedidparser.cpp 169
é¢æ°ã¯ã次ã®ã¢ã¯ã·ã§ã³ãå°å·ã§ããªãæåãããã·ã¥ââã«çœ®ãæããããå®è¡ããå¿ èŠããããŸãã ãããã圌女ã¯ããŸããã ãã®ç¶æ ã詳ããèŠãŠã¿ãŸãããã
if (buffer[i] < '\040' && buffer[i] > '\176')
æå³ããããŸããã æåãåæã«ã\ 040ãããå°ããããããšã¯ã§ãããã\ 176ããã倧ããããããšã¯ã§ããŸããã æ¡ä»¶ã§ã¯ãæŒç®åã||ãã䜿çšããå¿ èŠããããŸãã æ£ããã³ãŒãã¯æ¬¡ã®ãšããã§ãã
if (buffer[i] < '\040' || buffer[i] > '\176')
æ¬ é¥N72
åæ§ã®ãšã©ãŒãWindowsãŠãŒã¶ãŒã¯å¹žéã§ã¯ãããŸããã
#if defined(Q_OS_WIN) static QString driveSpec(const QString &path) { if (path.size() < 2) return QString(); char c = path.at(0).toLatin1(); if (c < 'a' && c > 'z' && c < 'A' && c > 'Z') return QString(); if (path.at(1).toLatin1() != ':') return QString(); return path.mid(0, 2); } #endif
ã¢ãã©ã€ã¶ãŒã¯ã2ã€ã®èŠåãäžåºŠã«çæããŸãã
- V590 CWE-571 'c <' a '&& c>' z '&& c <' A '&& c>' Z ''åŒã®æ€æ»ãæ€èšããŠãã ããã è¡šçŸãéå°ã§ãããã誀æ€ãå«ãŸããŠããŸãã qdir.cpp 77
- V560 CWE-570æ¡ä»¶åŒã®äžéšãåžžã«falseã§ãïŒc> 'z'ã qdir.cpp 77
è«çãšã©ãŒã¯æ¬¡ã®ç¶æ ã§ãã
if (c < 'a' && c > 'z' && c < 'A' && c > 'Z')
ç§ãç解ããŠããããã«ãããã°ã©ããŒã¯ã©ãã³ã¢ã«ãã¡ãããã®æåã§ã¯ãªãæåãèŠã€ããããšæã£ãŠããŸããã ãã®å Žåãæ¡ä»¶ã¯æ¬¡ã®ããã«ãªããŸãã
if ((c < 'a' || c > 'z') && (c < 'A' || c > 'Z'))
æ¬ é¥N73
enum SelectionMode { NoSelection, SingleSelection, MultiSelection, ExtendedSelection, ContiguousSelection }; void QAccessibleTableCell::unselectCell() { QAbstractItemView::SelectionMode selectionMode = view->selectionMode(); if (!m_index.isValid() || (selectionMode & QAbstractItemView::NoSelection)) return; .... }
PVS-StudioèŠåïŒV616 CWE-480å€ã0ã®ãQAbstractItemView :: NoSelectionããšããååã®å®æ°ããããæŒç®ã§äœ¿çšãããŸãã itemviews.cpp 976
ååä»ãå®æ°QAbstractItemView :: NoSelectionã¯ãŒãã§ãã ãããã£ãŠã å¯æ¬¡åŒïŒselectionModeããã³QAbstractItemView :: NoSelectionïŒã¯æå³ããããŸããã åžžã«0ã«ãªããŸãã
ç§ã¯ãããããã«æžãããã¹ãã ãšæãïŒ
if (!m_index.isValid() || (selectionMode == QAbstractItemView::NoSelection))
æ¬ é¥N74
次ã®ã³ãŒããç解ããã®ã¯é£ããã§ãã 圌ã¯ééã£ãŠããŸãããç§ã¯åœŒãã©ãããã¹ããããããŸããã é¢æ°ã«ã³ã¡ã³ãããããšãå©ãã«ã¯ãªããŸããã
// Re-engineered from the inline function _com_error::ErrorMessage(). // We cannot use it directly since it uses swprintf_s(), which is not // present in the MSVCRT.DLL found on Windows XP (QTBUG-35617). static inline QString errorMessageFromComError(const _com_error &comError) { TCHAR *message = nullptr; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, DWORD(comError.Error()), MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), message, 0, NULL); if (message) { const QString result = QString::fromWCharArray(message).trimmed(); LocalFree(static_cast<HLOCAL>(message)); return result; } if (const WORD wCode = comError.WCode()) return QString::asprintf("IDispatch error #%u", uint(wCode)); return QString::asprintf("Unknown error 0x0%x", uint(comError.Error())); }
PVS-StudioèŠåïŒV547 CWE-570åŒ 'message'ã¯åžžã«falseã§ãã qwindowscontext.cpp 802
ããããããã°ã©ããŒã¯ã FormatMessageé¢æ°ãã¡ãã»ãŒãžãã€ã³ã¿ãŒã®å€ãå€æŽãããšæ³å®ããŠããŸãã ããããããã¯ããã§ã¯ãããŸããã FormatMessageé¢æ°ã¯ãå€ã«ãã£ãŠé¢æ°ã«æž¡ãããããããã€ã³ã¿ãŒã®å€ãå€æŽã§ããŸããã ãã®é¢æ°ã®ãããã¿ã€ãã¯æ¬¡ã®ãšããã§ãã
DWORD __stdcall FormatMessageW( DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments );
æœåšçãªã¡ã¢ãªãªãŒã¯
é害N75-N92
struct SourceDependChildren { SourceFile **children; int num_nodes, used_nodes; SourceDependChildren() : children(nullptr), num_nodes(0), used_nodes(0) { } ~SourceDependChildren() { if (children) free(children); children = nullptr; } void addChild(SourceFile *s) { if(num_nodes <= used_nodes) { num_nodes += 200; children = (SourceFile**)realloc(children, sizeof(SourceFile*)*(num_nodes)); } children[used_nodes++] = s; } };
PVS-StudioèŠåïŒV701 CWE-401 reallocïŒïŒãªãŒã¯ã®å¯èœæ§ïŒreallocïŒïŒãã¡ã¢ãªã®å²ãåœãŠã«å€±æãããšãå ã®ãã€ã³ã¿ãåãã倱ãããŸãã reallocïŒïŒãäžæãã€ã³ã¿ãŒã«å²ãåœãŠãããšãæ€èšããŠãã ããã makefiledeps.cpp 103
ãããã¡æ¡åŒµã¯å±éºãªæ¹æ³ã§å®è£ ãããŸãã reallocé¢æ°ãã¡ã¢ãªãå²ãåœãŠãããªãå Žåã NULLãè¿ããŸã ã ãã®NULLã¯ããã«childrenå€æ°ã«çœ®ããã以åã«å²ãåœãŠããããããã¡ãŒãäœããã®æ¹æ³ã§è§£æŸããå¯èœæ§ã¯ãããŸããã ã¡ã¢ãªãªãŒã¯ãçºçããŸãã
åæ§ã®ãšã©ãŒïŒ qt-701.txt
ãã®ä»
æ¬ é¥N93
template<class GradientBase, typename BlendType> static inline const BlendType * QT_FASTCALL qt_fetch_linear_gradient_template(....) { .... if (t+inc*length < qreal(INT_MAX >> (FIXPT_BITS + 1)) && t+inc*length > qreal(INT_MIN >> (FIXPT_BITS + 1))) { .... }
PVS-StudioèŠåïŒV610 CWE-758äžç¹å®ã®åäœã ã·ããæŒç®åã>>ãã確èªããŠãã ããã å·Šã®ãªãã©ã³ã 'ïŒ-2147483647-1ïŒ'ã¯è² ã§ãã qdrawhelper.cpp 4015
INT_MINã®è² ã®å€ã¯ã·ããã§ããŸããã ããã¯äžç¹å®ã®åäœã§ããããã®ãããªæäœã®çµæã«äŸåããããšã¯ã§ããŸããã æäžäœãããã¯0ãŸãã¯1ã«çãããªããŸãã
æ¬ é¥N94
void QObjectPrivate::addConnection(int signal, Connection *c) { .... if (signal >= connectionLists->count()) connectionLists->resize(signal + 1); ConnectionList &connectionList = (*connectionLists)[signal]; .... if (signal < 0) { .... }
PVS-StudioèŠåïŒV781 CWE-129ãsignalãå€æ°ã®å€ã¯ã䜿çšåŸã«ãã§ãã¯ãããŸãã ãããããããã°ã©ã ããžãã¯ã«ééãããããŸãã è¡ã確èªïŒ397ã413ãqobject.cpp 397
ãã§ãã¯ïŒã·ã°ãã«<0ïŒã¯ã ã·ã°ãã«åŒæ°ã®å€ãè² ã«ãªãå¯èœæ§ãããããšã瀺ããŸãã ãã ãããã®åŒæ°ã¯ä»¥åã«é åã®ã€ã³ããã¯ã¹ä»ãã«äœ¿çšãããŠããŸããã ãã§ãã¯ã®å®è¡ãé ãããããšãããããŸããã ããã°ã©ã ã¯æ¢ã«äžæãããŸãã
æ¬ é¥N95
bool QXmlStreamWriterPrivate::finishStartElement(bool contents) { .... if (inEmptyElement) { write("/>"); QXmlStreamWriterPrivate::Tag &tag = tagStack_pop(); lastNamespaceDeclaration = tag.namespaceDeclarationsSize; lastWasStartElement = false; } else { write(">"); } inStartElement = inEmptyElement = false; lastNamespaceDeclaration = namespaceDeclarations.size(); return hadSomethingWritten; }
PVS-StudioèŠåïŒV519 CWE-563 'lastNamespaceDeclaration'å€æ°ã«ã¯é£ç¶ããŠ2åå€ãå²ãåœãŠãããŸãã ããããããã¯ééãã§ãã è¡ã確èªããŠãã ããïŒ3188ã3194ãqxmlstream.cpp 3194
ãšã©ãŒã®æ¬è³ªã匷調ããŸãã
if (inEmptyElement) { lastNamespaceDeclaration = tag.namespaceDeclarationsSize; } lastNamespaceDeclaration = namespaceDeclarations.size();
æ¬ é¥N96
void QRollEffect::scroll() { .... if (currentHeight != totalHeight) { currentHeight = totalHeight * (elapsed/duration) + (2 * totalHeight * (elapsed%duration) + duration) / (2 * duration); // equiv. to int((totalHeight*elapsed) / duration + 0.5) done = (currentHeight >= totalHeight); } done = (currentHeight >= totalHeight) && (currentWidth >= totalWidth); .... }
V519 CWE-563 'done'å€æ°ã«ã¯é£ç¶ããŠ2åå€ãå²ãåœãŠãããŸãã ããããããã¯ééãã§ãã è¡ã確èªããŠãã ããïŒ509ã511ãqeffects.cpp 511
ãã¹ãŠãåã®ã±ãŒã¹ãšåãã§ãã doneå€æ°ã«æ³šæããŠãã ããã
ãããã«
ã¬ããŒããè¡šé¢çã«èŠãŠããã»ãŒ100åã®ãšã©ãŒãæžããŸããã PVS-Studioã®çµæã«æºè¶³ããŠããŸãã
ãã¡ããããã®ãããªãŸããªã³ãŒããã§ãã¯ã¯ãã³ãŒãã®å質ãšä¿¡é Œæ§ã®åäžãšã¯é¢ä¿ãããŸããã ã³ãŒãã¢ãã©ã€ã¶ãŒã®æ©èœã®ã¿ã瀺ããŸãã éç解æããŒã«ã¯å®æçã«é©çšããå¿ èŠããããŸãã ãã®å Žåããã°ä¿®æ£ã®ã³ã¹ããåæžããå€ãã®æœåšçãªè匱æ§ããã¢ããªã±ãŒã·ã§ã³ãä¿è·ããŸãã
ãæž èŽããããšãããããŸããã ç§ãã¡ã®æ°ããåºçç©ã«é ããªãããã«ããããã«ãç§ãã¡ã®ãã£ã³ãã«ã®ããããã«ãµãã¹ã¯ã©ã€ãããããšãå§ããŸãã
- VK.comïŒpvsstudio_rus
- ãå€ãåŠæ ¡ãRSSïŒ viva64-blog-ru
- ãã€ãã¿ãŒïŒ @pvsstudio_rus
- InstagramïŒ @pvsstudio_rus
- é»å ±ïŒ @pvsstudio_rus
ãã®èšäºãè±èªåã®èŽè¡ãšå ±æãããå Žåã¯ã翻蚳ãžã®ãªã³ã¯ã䜿çšããŠãã ããïŒAndrey Karpovã PVS-Studioã䜿çšããQt 5ã®3çªç®ã®ãã§ãã¯