ããã¯ãVisual C ++ã«å«ãŸããã©ã€ãã©ãªã®ãã§ãã¯ã«é¢ãã2çªç®ã®èšäºã§ãã 以åã®ãã§ãã¯ã®çµæã¯ãèšäºã Visual C ++ 2012ã©ã€ãã©ãªã§ãšã©ãŒãæ€åºãããŸãããã§ç¢ºèªã§ããŸã ã
ã©ã€ãã©ãªå šäœã確èªã§ããŸããã ç§ã¯éåžžã«äžåšçšã«è¡åããŸããã æ°ãããããžã§ã¯ãã«ã¯ããã©ã«ããŒãcrt \ srcããšãatlmfc \ srcãã«å«ãŸãããã¹ãŠã®ãã¡ã€ã«ãå«ãŸããŠããŸãã ããã«ãæ°ããtest.cppãã¡ã€ã«ãäœæããŸããããã®ãã¡ã€ã«ã«ã¯ãæšæºã©ã€ãã©ãªïŒãã¯ã¿ãŒãããããã»ãããªã©ïŒã«é¢é£ãããã¹ãŠã®ããããŒãã¡ã€ã«ãå«ãŸããŠããŸãã
ãã®åŸããããžã§ã¯ãã®èšå®ãå°ãæãèµ·ãããŠããã¡ã€ã«ã®çŽ80ïŒ ãã³ã³ãã€ã«ãããããšãå®çŸããŸããã ããã§ååã ãšæããŸãã ãã¡ã€ã«ãã³ã³ãã€ã«ãããªãå Žåã§ããå®å šã§ã¯ãªããšããŠããã»ãšãã©ã®å ŽåPVS-Studioã«ãã£ãŠãã§ãã¯ãããŸãã
ãã®èšäºãå³æžé€šã®éçºè ã«ãšã£ãŠèå³æ·±ããã®ã§ããã°ã圌ãã¯ãã培åºçãªåæãè¡ãããšãã§ãããšæããŸãã ã¢ã»ã³ããªããšããŸããã¯ãªæ¹æ³ã§å®è¡ããããšããŠããä»ã§ã¯åé¡ã«ãªããŸããã ã³ã³ãã€ã©ãŒèµ·å远跡ã¡ã«ããºã ã䜿çšã§ããŸãã
æ€èšŒã«ã¯ã PVS-StudioããŒãžã§ã³5.19ã䜿çšããŸããã Visual Studio 2013ïŒã¢ããããŒã3ïŒã«å«ãŸããC / C ++ã©ã€ãã©ãªã®ãœãŒã¹ã³ãŒãã確èªããŸããã
ãã§ãã¯çµæ
Visual Studio 2012ã®ä»¥åã®ããŒãžã§ã³ã§èŠã€ãã£ãããã€ãã®æ¬ ç¹ã«ééããŸãããããšãã°ãprojïŒïŒé¢æ°ã¯ãŸã å¥åŠã«èŠããŸããããsingle_link_registryïŒïŒãã¹ãã©ã¯ã¿ã¯å±éºã§ãã ããããç¹°ãè¿ãããšã¯é¢çœããããŸããã äœãæ°ãããã®ãèŠã€ããŠã¿ãŸãããã
誀ã£ãã€ã³ããã¯ã¹ãã§ãã¯
void _Initialize_order_node(...., size_t _Index, ....) { if (_Index < 0) { throw std::invalid_argument("_Index"); } .... }
PVS-Studio èŠå ïŒ V547åŒ '_Index <0'ã¯åžžã«falseã§ãã 笊å·ãªãã®åã®å€ã<0ã«ãªãããšã¯ãããŸããã
åŒæ°ã¯_Indexã§ããã笊å·ãªãã®åãæã¡ãŸãã ãããã£ãŠãæ€èšŒã¯æå³ããããŸããã äŸå€ã¯æ±ºããŠã¹ããŒãããŸããã ããã¯ééãã§ã¯ãªããäœåãªã³ãŒãã ãšæããŸãã
ãã©ãŒããããšã©ãŒ
int _tfpecode; /* float point exception code */ void __cdecl _print_tiddata1 ( _ptiddata ptd ) { .... printf("\t_gmtimebuf = %p\n", ptd->_gmtimebuf); printf("\t_initaddr = %p\n", ptd->_initaddr); printf("\t_initarg = %p\n", ptd->_initarg); printf("\t_pxcptacttab = %p\n", ptd->_pxcptacttab); printf("\t_tpxcptinfoptrs = %p\n", ptd->_tpxcptinfoptrs); printf("\t_tfpecode = %p\n\n", ptd->_tfpecode); .... }
èŠåPVS-StudioïŒ V576ã®åœ¢åŒãæ£ãããããŸãã ã 'printf'é¢æ°ã®2çªç®ã®å®åŒæ°ã確èªããããšãæ€èšããŠãã ããã ãã€ã³ã¿ãŒã¯åŒæ°ãšããŠæåŸ ãããŠããŸãã tidprint.c 133
ããã§ã¯ãæåŸã®è¡ã®å¹æãæ±ã£ãŠããŸã ã åãã¿ã€ãã®è¡ã®ãããã¯ã®æåŸã§ãšã©ãŒãçºçããŸããã ã©ãã§ããã€ã³ã¿ã®å€ãå°å·ããå¿ èŠããããŸãã ããããæåŸã«ãå€æ°ã_tfpecodeãã¯ãã€ã³ã¿ãŒã§ã¯ãªããåãªãæŽæ°å€ã§ãã ããã¯æžãããã¹ãã§ãïŒ
printf("\t_tfpecode = %i\n\n", ptd->_tfpecode);
å¥åŠãªç¹°ãè¿ãèšç®
unsigned int SchedulerProxy::AdjustAllocationIncrease(....) const { .... unsigned int remainingConcurrency = m_maxConcurrency - m_currentConcurrency; remainingConcurrency = m_maxConcurrency - m_currentConcurrency; .... }
PVS-StudioèŠåïŒ V519 ãremainingConcurrencyãå€æ°ã«ã¯é£ç¶ããŠ2åå€ãå²ãåœãŠãããŸãã ããããããã¯ééãã§ãã è¡ã確èªããŠãã ããïŒ1136ã1137ãschedulerproxy.cpp 1137
å€æ°ã«ã¯ãåãåŒã®çµæã2åå²ãåœãŠãããŸãã ãã®ã³ãŒãã¯åé·ã§ããããªãã¡ã¯ã¿ãªã³ã°ã®å€±æãåå ã§ããå¯èœæ§ãé«ãã§ãã
ã¿ã€ããã¹ã®çã
double HillClimbing::CalculateThroughputSlope(....) { .... MeasuredHistory * lastHistory = GetHistory(fromSetting); MeasuredHistory * currentHistory = GetHistory(toSetting); .... double varianceOfcurrentHistory = currentHistory->VarianceMean(); double varianceOflastHistory = currentHistory->VarianceMean(); .... }
PVS-StudioèŠåïŒ V656å€æ° 'varianceOfcurrentHistory'ã 'varianceOflastHistory'ã¯ãåãé¢æ°ã®åŒã³åºãã«ãã£ãŠåæåãããŸãã ãããããšã©ãŒãŸãã¯æé©åãããŠããªãã³ãŒãã§ãã ãcurrentHistory-> VarianceMeanïŒïŒãåŒã®æ€æ»ãæ€èšããŠãã ããã è¡ã確èªããŠãã ããïŒ412ã413ãhillclimbing.cpp 413
å€æ°varianceOfcurrentHistoryãšvarianceOflastHistoryã«åãå€ãå²ãåœãŠãããŠããã®ã¯çãããã§ãã 次ã®ããã«varianceOflastHistoryãåæåããããšã¯è«ççã§ãïŒ
double varianceOflastHistory = varianceOfcurrentHistory;
ããã«ããlastHistoryããžã®ãã€ã³ã¿ããŸã ãããŸãã ã³ãŒãã«ã¿ã€ããã¹ãå«ãŸããŠããããšãææ¡ãããŠãã ããã ãããããã³ãŒãã¯æ¬¡ã®ããã«ãªããŸãã
double varianceOfcurrentHistory = currentHistory->VarianceMean(); double varianceOflastHistory = lastHistory->VarianceMean();
ãããŠãããã¯ãŸãã«ã¿ã€ããã¹ã§ã
BOOL CPropertySheet::SetActivePage(CPropertyPage* pPage) { ASSERT_VALID(this); ENSURE_VALID(pPage); ASSERT_KINDOF(CPropertyPage, pPage); int nPage = GetPageIndex(pPage); ASSERT(pPage >= 0); return SetActivePage(nPage); }
PVS-StudioèŠåïŒ V503ããã¯ç¡æå³ãªæ¯èŒã§ãïŒpointer> =0ãdlgprop.cpp 1206
ãã€ã³ã¿ãŒå€ããŒã以äžã§ããããšã確èªããã®ã¯å¥åŠã§ãã ããã¯ã¿ã€ããã¹ã§ãããå®éãå€æ°ãnPageãã確èªãããã£ãã®ã§ãã
int nPage = GetPageIndex(pPage); ASSERT(nPage >= 0);
ãã¡ãããããã¯åãªãã¢ãµãŒãã§ããããšã©ãŒããã€ãã¹ã®çµæãããããããšã¯ãããŸããã ããã§ããããã¯ééãã§ãã
æ¡ä»¶ã«é¢ä¿ãªãåãã¢ã¯ã·ã§ã³
void CMFCVisualManager::OnDrawTasksGroupCaption(....) { .... if (pGroup->m_bIsSpecial) { if (!pGroup->m_bIsCollapsed) { CMenuImages::Draw(pDC, CMenuImages::IdArrowUp, rectButton.TopLeft()); } else { CMenuImages::Draw(pDC, CMenuImages::IdArrowDown, rectButton.TopLeft()); } } else { if (!pGroup->m_bIsCollapsed) { CMenuImages::Draw(pDC, CMenuImages::IdArrowUp, rectButton.TopLeft()); } else { CMenuImages::Draw(pDC, CMenuImages::IdArrowDown, rectButton.TopLeft()); } } .... }
PVS-StudioèŠåïŒ V523 ãthenãã¹ããŒãã¡ã³ãã¯ãelseãã¹ããŒãã¡ã³ããšåçã§ãã afxvisualmanager.cpp 2118
æ¡ä»¶ã«é¢ä¿ãªãïŒpGroup-> m_bIsSpecialïŒãåãã¢ã¯ã·ã§ã³ãå®è¡ãããŸãã ããã¯å¥åŠã§ãã
誀ã£ãããŒãçªå·ã®æ€èšŒ
typedef WORD ATL_URL_PORT; ATL_URL_PORT m_nPortNumber; inline BOOL Parse(_In_z_ LPCTSTR lpszUrl) { .... m_nPortNumber = (ATL_URL_PORT) _ttoi(tmpBuf); if (m_nPortNumber < 0) goto error; .... }
PVS-Studio èŠå ïŒ V547åŒ 'm_nPortNumber <0'ã¯åžžã«falseã§ãã 笊å·ãªãã®åã®å€ã<0ã«ãªãããšã¯ãããŸããatlutil.h 2773
å€æ° 'm_nPortNumber'ã«ã¯ã笊å·ãªãã®WORDã¿ã€ãããããŸãã
ä»®æ³ãã¹ãã©ã¯ã¿ãªã
class CDataSourceControl { .... ~CDataSourceControl(); .... virtual IUnknown* GetCursor(); virtual void BindProp(....); virtual void BindProp(....); .... } CDataSourceControl* m_pDataSourceControl; COleControlSite::~COleControlSite() { .... delete m_pDataSourceControl; .... }
èŠåPVS_StudioïŒ V599 ãCDataSourceControlãã¯ã©ã¹ã«ã¯ä»®æ³é¢æ°ãå«ãŸããŠããŸããããã¹ãã©ã¯ã¿ã¯ä»®æ³ãã¹ãã©ã¯ã¿ãšããŠå®£èšãããŠããŸããã occsite.cpp 77
CDataSourceControlã¯ã©ã¹ã«ã¯ä»®æ³ã¡ãœãããå«ãŸããŠããŸããããã¹ãã©ã¯ã¿ã¯ä»®æ³ã§ã¯ãããŸããã ããã¯å±éºã§ãã ã¯ã©ã¹XãCDataSourceControlã¯ã©ã¹ããç¶æ¿ãããŠããå Žåãåºæ¬ã¯ã©ã¹ãžã®ãã€ã³ã¿ãŒã䜿çšããŠãã¿ã€ãXã®ãªããžã§ã¯ããç Žæ£ããããšã¯ã§ããŸããã
äžå®å šãªã³ãŒã
BOOL CMFCWindowsManagerDialog::OnHelpInfo(HELPINFO* pHelpInfo) { pHelpInfo->iCtrlId; CWnd* pParentFrame = AfxGetMainWnd(); pParentFrame->SendMessage(AFX_WM_WINDOW_HELP, 0, (LPARAM) this); return FALSE; }
èŠåPVS_StudioïŒ V607ææè ãªãã®åŒ 'pHelpInfo-> iCtrlId'ã afxwindowsmanagerdialog.cpp 472
ãpHelpInfo-> iCtrlId;ããšã¯äœã§ããïŒ ããã¯ã©ãããæå³ã§ããïŒ
çãããäºéåæå
CMFCStatusBar::CMFCStatusBar() { m_hFont = NULL; // setup correct margins m_cxRightBorder = m_cxDefaultGap; //<<-- m_cxSizeBox = 0; m_cxLeftBorder = 4; m_cyTopBorder = 2; m_cyBottomBorder = 0; m_cxRightBorder = 0; //<<-- .... }
PVS-StudioèŠåïŒ V519 ãm_cxRightBorderãå€æ°ã«ã¯ãé£ç¶ããŠ2åå€ãå²ãåœãŠãããŸãã ããããããã¯ééãã§ãã è¡ããã§ãã¯ïŒ74ã80ãafxstatusbar.cpp 80
æåã«ãå¥ã®å€æ°ã®å€ãå€æ°ãm_cxRightBorderãã«æžã蟌ãŸããŸãã ãããŠããã®å€ã¯çªç¶ãŒãã§äžæžããããŸãã
çãããã¹ããŒã¿ã¹ã®ç¢ºèª
#define S_OK ((HRESULT)0L) #define E_NOINTERFACE _HRESULT_TYPEDEF_(0x80004002L) HRESULT GetDocument(IHTMLDocument2** ppDoc) const { const T* pT = static_cast<const T*>(this); return pT->GetDHtmlDocument(ppDoc) ? S_OK : E_NOINTERFACE; } HRESULT GetEvent(IHTMLEventObj **ppEventObj) const { .... if (GetDocument(&sphtmlDoc)) .... }
PVS-StudioèŠåïŒ V545ãã®ãããªãifãæŒç®åã®æ¡ä»¶åŒã¯ãHRESULTåã®å€ãGetDocumentïŒïŒsphtmlDocïŒãã«å¯ŸããŠæ£ãããããŸããã 代ããã«SUCCEEDEDãŸãã¯FAILEDãã¯ãã䜿çšããå¿ èŠããããŸãã afxhtml.h 593
ã³ãŒãã®èšèšã¯ããã®äœæ¥ããžãã¯ã«å¯Ÿå¿ããŠããªãå ŽåããããŸãã æ¡ä»¶ 'GetDocumentïŒ...ïŒ'ãçã®å Žåãããã¥ã¡ã³ãããååŸãã§ããããã§ãã ããããå®éã«ã¯ããã§ã¯ãããŸããã GetDocumentïŒïŒé¢æ°ã¯ãHRESULTåã®å€ãè¿ããŸãã ãã®ã¿ã€ãã§ã¯ãéã®ããšãåœãŠã¯ãŸããŸãã ããšãã°ãã¹ããŒã¿ã¹S_OKã¯0ãšããŠãšã³ã³ãŒããããã¹ããŒã¿ã¹E_NOINTERFACEã¯0x80004002LãšããŠãšã³ã³ãŒããããŸãã ã¿ã€ãHRESULTã®å€ã確èªããã«ã¯ãç¹å¥ãªãã¯ãSUCCEEDEDãFAILEDã䜿çšããå¿ èŠããããŸãã
ããã«ãšã©ãŒããããã©ããã¯ããããŸãããããã®ã³ãŒãã¯ãããã«ããã®ã§ç¢ºèªããå¿ èŠããããŸãã
ãã¯ãMAKE_HRESULTã®åŒæ°ãç¡å¹ã§ã
#define MAKE_HRESULT(sev,fac,code) \ ((HRESULT) \ (((unsigned long)(sev)<<31) | \ ((unsigned long)(fac)<<16) | \ ((unsigned long)(code))) ) ATLINLINE ATLAPI AtlSetErrorInfo(....) { .... hRes = MAKE_HRESULT(3, FACILITY_ITF, nID); .... }
PVS-Studio èŠå ïŒ V673 ãïŒunsigned longïŒïŒ3ïŒ<< 31ãåŒã¯6442450944ã«è©äŸ¡ãããŸããå€ãä¿åããã«ã¯33ããããå¿ èŠã§ãããåŒã¯ã32ãã®ã¿ãä¿æã§ãããunsignedãã¿ã€ãã«è©äŸ¡ãããŸããããã atlcom.h 6650
ãã¹ãŠãæ£ããæ©èœããŸãããééãããããŸãã 説æããŸãã
é¢æ°ã¯ãHRESULTåã®å€æ°ã«ãšã©ãŒæ å ±ãçæããå¿ èŠããããŸãã ãããè¡ãã«ã¯ããã¯ãMAKE_HRESULTã䜿çšããŸãã ããããããã¯èª€ã£ãŠäœ¿çšãããŸãã ããã°ã©ããŒã¯ãæåã®ãã©ã¡ãŒã¿ãŒãé倧床ãã0ãã3ãŸã§ã®éè·¯ã«ãããšèããŸãããã©ãããããããGetLastErrorïŒïŒ/ SetLastErrorïŒïŒé¢æ°ãæäœãããšãã«äœ¿çšããããšã©ãŒã³ãŒããçæããæ¹æ³ãšæ··åããããã§ãã
MAKE_HRESULTãã¯ãã¯ãæåã®åŒæ°ãšããŠ0ïŒæåïŒãŸãã¯1ïŒå€±æïŒã®ã¿ãåãå ¥ããŸãã ãã®åé¡ã¯ãCodeGuruã®Webãµã€ããã©ãŒã©ã ã§è©³çŽ°ã«èª¬æãããŠããŸãïŒèŠåïŒ MAKE_HRESULTãã¯ãã¯æ©èœããŸããã
æ°å€3ãæåã®å®åŒæ°ãšããŠäœ¿çšãããããããªãŒããŒãããŒãçºçããŸãã çªå·3ã¯1ã«å€ãããŸãããã®ã©ã³ãã æ§ã®ããããšã©ãŒã¯ããã°ã©ã ã«åœ±é¿ããŸããã
æ¡ä»¶ãåžžã«çã§ããASSERT
ASSERTã®æ¡ä»¶ã次ã®ããã«èŠããç¶æ³ã¯ããªããããŸãïŒïŒX> = 0ïŒã ãã®å Žåãå€æ°Xã¯ç¬Šå·ãªãæŽæ°åãšããŠå®£èšãããŸãã æ¡ä»¶ã¯åžžã«çã§ããããšãããããŸãã
å Žåã«ãã£ãŠã¯ããã®ãããªASSERTã®ååšã¯åççã§ãã çªç¶ããªãã¡ã¯ã¿ãªã³ã°ããã»ã¹äžã«å€æ°ãéèŠã«ãªããã¢ã«ãŽãªãºã ã¯è² ã®æ°ãåŠçããæºåãã§ããŠããŸããã ãã ãããããã®ããã€ãã®ååšã¯ã»ãšãã©ç¡æå³ã§ãã ã³ãŒãããåé€ããããå¥ã®äŸ¿å©ãªãã§ãã¯ã«çœ®ãæããå¿ èŠããããŸãã ãããã£ãŠãç§ã¯ããããèšäºã§èšåããããšã«ããŸããã
äŸãèããŠã¿ãŸãããïŒ
DWORD m_oversubscribeCount; void ExternalContextBase::Oversubscribe(....) { if (beginOversubscription) { ASSERT(m_oversubscribeCount >= 0); ++m_oversubscribeCount; } .... }
PVS-Studioã®èŠå ïŒ V547åŒ 'm_oversubscribeCount> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> = 0ã§ããexternalcontextbase.cpp 204
æ®ãã®èŠåã¯åãªããªã¹ãã§ãã
- V547åŒ 'm_oversubscribeCount> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> = 0ã§ããinternalcontextbase.cpp 506
- V547åŒ 'pGlobalNode-> m_idleCores> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> 0ã§ããresourcemanager.cpp3764
- V547åŒ 'pGlobalNode-> m_availableCores> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> 0ã§ããresourcemanager.cpp3769
- V547åŒ 'pReceivingProxyData-> m_allocation> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> 0ã§ããresourcemanager.cpp4100
- V547åŒ 'pReceivingProxyData-> m_allocation> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> 0ã§ããresourcemanager.cpp4360
- V547åŒ 'exclusiveCoresAvailable> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> 0ã§ããresourcemanager.cpp4657
- V547åŒ 'coresNeeded> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> 0ã§ããresourcemanager.cpp4657
- V547åŒ 'previousGlobal> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> 0ã§ããresourcemanager.cpp4781
- V547åŒ 'currentGlobal> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®ã¿ã€ãã®å€ã¯åžžã«> 0ã§ããresourcemanager.cpp4782
- V547åŒ 'm_minConcurrency> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> 0ã§ããschedulerproxy.cpp 63
- V547åŒ 'm_minimumHardwareThreads> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> 0ã§ããschedulerproxy.cpp 125
- V547åŒ 'm_oversubscribeCount> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> = 0ã§ããumsthreadinternalcontext.cpp308
- V547åŒ 'j> = 0'ã¯åžžã«çã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> = 0ã§ããresourcemanager.cpp1922
- V547åŒ 'pMaxNode-> m_availableCores> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> 0ã§ããresourcemanager.cpp2542
- V547åŒ 'previousLocal> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> 0ã§ããresourcemanager.cpp4793
- V547åŒ 'currentLocal> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®ã¿ã€ãã®å€ã¯åžžã«> 0ã§ããresourcemanager.cpp4794
- V547åŒã¯åžžã«çã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> 0ã§ããschedulerpolicybase.cpp 285
- V547åŒ 'value> = 0'ã¯åžžã«trueã§ãã 笊å·ãªãã®åã®å€ã¯åžžã«> = 0ã§ããschedulerpolicybase.cpp 345
äœåãªãã£ã¹ã
äžèŠãªã ãã§ãªããå€ãå°ç¡ãã«ããå¯èœæ§ãããæ瀺çãªåå€æãããã€ããããŸããã
æåã®äŸãèããŠã¿ãŸãããïŒ
size_t __cdecl strnlen(const char *str, size_t maxsize); size_t __cdecl _mbstrnlen_l(const char *s, size_t sizeInBytes, _locale_t plocinfo) { .... if ( _loc_update.GetLocaleT()->locinfo->mb_cur_max == 1 ) /* handle single byte character sets */ return (int)strnlen(s, sizeInBytes); .... }
PVS-Studio èŠå ïŒ V220åãã£ã¹ãã®äžå¯©ãªã·ãŒã±ã³ã¹ïŒmemsize-> 32ãããæŽæ°-> memsizeã ãã£ã¹ããããå€ïŒ 'strnlenïŒsãsizeInBytesïŒ'ã _mbslen_s.c 67
strnlenïŒïŒé¢æ°ã¯ã 'size_t'åã®å€ãè¿ããŸãã ãã®åŸãçªç¶æ瀺çã« 'int'åã«ãªããŸãã ãã®åŸãå€ã¯æé»çã«åã³size_tåã«å±éãããŸãã
ãã®ã³ãŒãã«ã¯ãæœåšçãª64ããããšã©ãŒãå«ãŸããŠããŸãã çªç¶ã64ãããããã°ã©ã ã§_mbstrnlen_lïŒïŒé¢æ°ã䜿çšããŠéåžžã«é·ãè¡ã®æåæ°ãã«ãŠã³ããããå Žåãééã£ãçµæãè¿ãããŸãã
ãã®æ瀺çãªãã£ã¹ãã¯å¶ç¶ã«ã³ãŒãã«æ®ã£ãŠãããããåã«åé€ããå¿ èŠãããããã«æããŸãã
2çªç®ã®äŸãèããŠã¿ãŸãããã
WINBASEAPI SIZE_T WINAPI GlobalSize (_In_ HGLOBAL hMem); inline void __cdecl memcpy_s( _Out_writes_bytes_to_(_S1max,_N) void *_S1, _In_ size_t _S1max, _In_reads_bytes_(_N) const void *_S2, _In_ size_t _N); AFX_STATIC HGLOBAL AFXAPI _AfxCopyGlobalMemory(....) { ULONG_PTR nSize = ::GlobalSize(hSource); .... Checked::memcpy_s(lpDest, (ULONG)::GlobalSize(hDest), lpSource, (ULONG)nSize); .... }
PVS-StudioèŠåïŒV220çãããåãã£ã¹ãïŒmemsize-> 32ãããæŽæ°-> memsizeã ãã£ã¹ããããå€ïŒ 'nSize'ã olemisc.cpp 684ã
GlobalSizeïŒïŒé¢æ°ã¯ãã¿ã€ãSIZE_Tãè¿ããŸãã memcpy_sïŒïŒã®åŒæ°ãsize_tåã§ãã
ã§ã¯ããªããïŒULONGïŒ:: GlobalSizeïŒhDestïŒãã®ãããªæ瀺çãªãã£ã¹ããè¡ãããã®ã§ããïŒ
4Gbãã倧ãããããã¡ãŒã䜿çšããå Žåãmemcpy_sïŒïŒé¢æ°ã¯é åã®äžéšã®ã¿ãã³ããŒããŸãã
ããã«çãããåå€æãããã€ããããŸãã
- V220åãã£ã¹ãã®äžå¯©ãªã·ãŒã±ã³ã¹ïŒmemsize-> 32ãããæŽæ°-> memsizeã ãã£ã¹ããããå€ïŒ 'wcslenïŒ* vp ++ïŒ'ã cenvarg.c 236
- V220åãã£ã¹ãã®äžå¯©ãªã·ãŒã±ã³ã¹ïŒmemsize-> 32ãããæŽæ°-> memsizeã ãã£ã¹ããããå€ïŒ ':: GlobalSizeïŒm_hGlobalMemoryïŒ'ã fileshrd.cpp 48
- V220åãã£ã¹ãã®äžå¯©ãªã·ãŒã±ã³ã¹ïŒmemsize-> 32ãããæŽæ°-> memsizeã ãã£ã¹ããããå€ïŒ 'wcslenïŒlpszïŒ'ã dumpcont.cpp 31
- V220åãã£ã¹ãã®äžå¯©ãªã·ãŒã±ã³ã¹ïŒmemsize-> 32ãããæŽæ°-> memsizeã ãã£ã¹ããããå€ïŒ 'wcslenïŒlpszïŒ'ã dumpcont.cpp 82
- V220åãã£ã¹ãã®äžå¯©ãªã·ãŒã±ã³ã¹ïŒmemsize-> 32ãããæŽæ°-> memsizeã ãã£ã¹ããããå€ïŒ 'ïŒcElems * sizeofïŒCLSIDïŒïŒ'ã ctlcore.cpp 1975
- V220åãã£ã¹ãã®äžå¯©ãªã·ãŒã±ã³ã¹ïŒmemsize-> 32ãããæŽæ°-> memsizeã ãã£ã¹ããããå€ïŒ 'wParam'ã afxtoolbarslistcheckbox.cpp 94
- V220åãã£ã¹ãã®äžå¯©ãªã·ãŒã±ã³ã¹ïŒmemsize-> 32ãããæŽæ°-> memsizeã ãã£ã¹ããããå€ïŒ 'nChars * sizeofïŒTCHARïŒ'ã statreg.h 270
æ€èšŒåã«äœ¿çš
CMFCPopupMenu* CMFCCustomizeButton::CreatePopupMenu() { .... if (m_pWndParentToolbar->IsLocked()) { pMenu->GetMenuBar()->m_pRelatedToolbar = m_pWndParentToolbar; } pMenu->m_bRightAlign = m_bMenuRightAlign && (m_pWndParentToolbar->GetExStyle() & WS_EX_LAYOUTRTL) == 0; BOOL bIsLocked = (m_pWndParentToolbar == NULL || m_pWndParentToolbar->IsLocked()); .... }
PVS-Studio èŠå ïŒ V595 nullptrã«å¯ŸããŠæ€èšŒãããåã«ããm_pWndParentToolbarããã€ã³ã¿ãŒã䜿çšãããŸããã è¡ã確èªããŠãã ããïŒ192ã199ãafxcustomizebutton.cpp 192
æåã¯ãåŒãm_pWndParentToolbar-> IsLockedïŒïŒãã§ãã€ã³ã¿ãŒãm_pWndParentToolbarããéåç §ãããŸãã ãããŠããŒããšçãããã©ããããã§ãã¯ãããŸãïŒ 'm_pWndParentToolbar == NULL'ã
ãã®ãããªã³ãŒãã¯å±éºã§ããããã®çç±ã説æãã䟡å€ã¯ãªããšæããŸãã
å¥ã®ãã®ãããªå ŽåïŒ
void COleControlSite::BindDefaultProperty(....) { .... if (pDSCWnd != NULL) { .... m_pDSCSite = pDSCWnd->m_pCtrlSite; .... m_pDSCSite->m_pDataSourceControl->BindProp(this, TRUE); if (m_pDSCSite != NULL) m_pDSCSite->m_pDataSourceControl->BindColumns(); } .... }
PVS-StudioèŠåïŒV595 nullptrã«å¯ŸããŠæ€èšŒãããåã«ããm_pDSCSiteããã€ã³ã¿ãŒã䜿çšãããŸããã ãã§ãã¯è¡ïŒ1528ã1528ãoccsite.cpp 1528
è¿œå å€æ°
äœåãªå€æ°ã¯ééãã§ã¯ãããŸããã ããããäœåãªã圌ãã¯äœåã§ãããããããåãé€ã䟡å€ããããŸãã äŸïŒ
int GetImageCount() const { CRect rectImage(m_Params.m_rectImage); if (m_Bitmap.GetCount() == 1) { HBITMAP hBmp = m_Bitmap.GetImageWell(); BITMAP bmp; if (::GetObject(hBmp, sizeof(BITMAP), &bmp) == sizeof(BITMAP)) { return bmp.bmHeight / m_Params.m_rectImage.Height(); } return 0; } return m_Bitmap.GetCount(); }
PVS-StudioèŠåïŒãCRectãã¿ã€ãã®V808 ãrectImageããªããžã§ã¯ããäœæãããŸãããã䜿çšãããŸããã§ããã afxcontrolrenderer.h 89
åè§åœ¢ãrectImageããäœæãããŸãããåŸã§äœ¿çšãããŸããã ããã°ã©ã å ã®äœåãªè¡ãšããããã°ããŒãžã§ã³ã®äœæ¥äžã®ããã€ãã®äœåãªãµã€ã¯ã«ã
èŠã€ãã£ãäžèŠãªå€æ°ã®ãªã¹ãã瀺ããŸãïŒ vs2003_V808.txt
ããããªããš
éåžžã«å€ãã®èŠåã¯ããšã©ãŒã§ã¯ãªããããã°ã©ãã³ã°ã¹ã¿ã€ã«ã®å€±æã«èµ·å ããå¯èœæ§ããããŸãã Visual C ++ã©ã€ãã©ãªã®ãœãŒã¹ã³ãŒãã¯ãããŒã«ã¢ãã«ãšããŠä»ã®ããã°ã©ããŒã«åœ¹ç«ã€ã¯ãã§ãã ãããã£ãŠã圌ãã«æªãããšãæããªãã§ãã ããã
æ¹åã§ããããã€ãã®ãã©ã°ã¡ã³ãããªã¹ãããŸãã
TRUEãšã®å±éºãªæ¯èŒ
_PHNDLR __cdecl signal(int signum, _PHNDLR sigact) { .... if ( SetConsoleCtrlHandler(ctrlevent_capture, TRUE) == TRUE ) .... }
PVS-StudioèŠåïŒ V676 BOOLåã®å€æ°ãTRUEãšæ¯èŒããã®ã¯æ£ãããããŸããã winsig.c 255
MSDNãå«ãããããå Žæã§ãäœããTRUEãšæ¯èŒããã®ã¯è¯ããªããšèšãããŠããŸãã ãã®é¢æ°ã¯0以å€ã®å€ãè¿ãããšãã§ããããã¯çãšèŠãªãããŸãã TRUEãããã¯1ã§ããæ¯èŒããã®ã¯åžžã«æ£ããã§ãïŒFooïŒïŒïŒ= FALSEã
åæ§ã®ãã§ãã¯ã¯ããã«ãããŸãïŒ
- V676 BOOLåã®å€æ°ãTRUEãšæ¯èŒããã®ã¯æ£ãããããŸããã event.cpp 448
- V676 BOOLåã®å€æ°ãTRUEãšæ¯èŒããã®ã¯æ£ãããããŸããã æ£ããè¡šçŸã¯ãretValïŒ= FALSEãã§ãã resourcemanager.cpp 1437
- V676 BOOLåã®å€æ°ãTRUEãšæ¯èŒããã®ã¯æ£ãããããŸããã æ£ããè¡šçŸã¯ãretValïŒ= FALSEãã§ãã resourcemanager.cpp 5027
ã€ã³ã¯ãªã¡ã³ã
void _To_array( ::Concurrency::details::_Dynamic_array<_EType>& _Array) { _LockHolder _Lock(_M_lock); _M_iteratorCount++; for(_LinkRegistry::iterator _Link = _M_links.begin(); *_Link != NULL; _Link++) { _Array._Push_back(*_Link); } }
èŠåPVS-StudioïŒ V803ããã©ãŒãã³ã¹ã®äœäžã '_Link'ãã€ãã¬ãŒã¿ã®å Žåããã¬ãã£ãã¯ã¹åœ¢åŒã®ã€ã³ã¯ãªã¡ã³ãã䜿çšããæ¹ãå¹æçã§ãã ã€ãã¬ãŒã¿++ã++ã€ãã¬ãŒã¿ã«çœ®ãæããŸãã agents.h 1713
ãã¡ããäºçŽ°ãªããšã§ãããã©ãã§ã++ã€ãã¬ãŒã¿ã䜿çšããããšããå§ãããŸãã å¯èœã§ããã°ãä»ã®äººã«æããããã®è¯ãã¹ã¿ã€ã«ã瀺ãããã«æ¥é èŸæŒç®åã䜿çšããã®ãæåã§ãã
ã泚æ ãã®ãããã¯ã«é¢ãã泚ïŒ
- åŸçœ®it ++ã®ä»£ããã«ãæ¥é èŸã€ã³ã¯ãªã¡ã³ãæŒç®å++ itãå埩åã«äœ¿çšããããšã¯å®çšçã§ããïŒ
- ãã¬vs. å¢ååŸæŒç®å-ãã³ãããŒã¯ ã
誀ã£ãèŠåã¬ãã«ã®å埩
#pragma warning (disable : 4311) SetClassLongPtr(m_hWnd, GCLP_HBRBACKGROUND, PtrToLong(reinterpret_cast<void*>( ::GetSysColorBrush(COLOR_BTNFACE)))); #pragma warning (default : 4311)
èŠåV665ãã®ã³ã³ããã¹ãã§ã¯ããïŒpragma warningïŒdefaultïŒXïŒãã®äœ¿çšãééã£ãŠããå¯èœæ§ããããŸãã 代ããã«ã#pragma warningïŒpush / popïŒãã䜿çšããå¿ èŠããããŸãã è¡ã確èªããŠãã ããïŒ165ã167ãafxbasepane.cpp 167
åã®èŠåç¶æ ã«æ»ãæ£ããæ¹æ³ã¯ããïŒpragma warningïŒpush [ãn]ïŒãããã³ã#pragma warningïŒpopïŒãã䜿çšããããšã§ãã
ãã®ä»ã®å ŽæïŒ vs2003_V665.txt
æ€èšŒïŒthis == NULLïŒ
ãžã£ã³ã«ã®å€å žïŒ
_AFXWIN_INLINE CWnd::operator HWND() const { return this == NULL ? NULL : m_hWnd; }
PVS-Studio èŠå ïŒ V704 'this == 0'åŒã¯é¿ããå¿ èŠããããŸã-'this 'ãã€ã³ã¿ãNULLã«ãªãããšã¯ãªãããããã®åŒã¯æ°ããã³ã³ãã€ã©ã§ã¯åžžã«falseã§ã afxwin2.inl 19
æ®å¿µãªãããããã¯éåžžã«äžè¬çãªãã¿ãŒã³ã§ãã ç¹ã«MFCã§ã ãããããã®ãããªãã¶ã€ã³ã䜿çšããããšãã人ã ãåŸã ã«åŒãé¢ããè¯ãäŸãèšå®ããããšã¯äŸ¡å€ããããŸãã
ãªããããæªãã®ããŸã ããããªãèªè ã®ããã«ã V704蚺æã®ããã¥ã¡ã³ãã«ç²Ÿéããããšãææ¡ããŸãã ããã«ã¯ãã¹ãŠã詳现ã«èª¬æãããŠããŸãã
æŒç®åHWNDïŒïŒãä¿®æ£ããæ¹æ³ããªãããšãç解ããŠããŸãã äžäœäºææ§ãéèŠã§ãã ããããçªç¶ã©ããã§ç°¡åã«ã§ããŸãã ãã®ãããªãã§ãã¯ã®ãªã¹ãïŒ vs2003_V704.txt
ãããã«
ã芧ã®ãšãããããªã倧ããªèšäºãèŠã€ãããŸããã ããããå®éã«ã¯ãéèŠãªãã®ã¯çºèŠãããŠããŸããã Visual C ++ã©ã€ãã©ãªã³ãŒãã¯ãç¬èªã®å質ã§ãããã°ãããŠããŸãã
ãã®èšäºãå°æ¥çã«Visual C ++ã©ã€ãã©ãªãå°ãè¯ãããã®ã«åœ¹ç«ã£ãŠããããå¬ããã§ãã ãã§ãã¯ãäžé©åã«å®è¡ãããããšãæ¹ããŠææããŸãã Visual C ++ã©ã€ãã©ãªã®éçºè ã¯ãã©ã€ãã©ãªãæ§ç¯ããããã®ã¹ã¯ãªãã/ãããžã§ã¯ããããããããããããå¹ççã«è¡ãããšãã§ããŸãã äœãåé¡ãããã°ãç§ã¯å©ããæºåãã§ããŠããŸã-ãµããŒãã§ç§ãã¡ã«æžããŠãã ããã
PSã ã²ãŒã ãéãŒã ãã®æçš¿ãèŠéãã人ã®ããã«ãããªãã®æ³šæåããã§ãã¯ããææ¡ããããã¹ãã«åæ Œããããšããå§ãããŸãã åæã«ããªããã¹ããæééãã«è¡ãããã®ããšãã質åã«çããããšæããŸãã ããã¯ãPVS-Studioãæ€åºãããšã©ãŒã15ç§ã§ç®ã§çºèŠããããšäž»åŒµãã人ã ã®ãããŒãªã³ã°ã§ãã
ãã®èšäºã¯è±èªã§ãã
ãã®èšäºãè±èªåã®èŽè¡ãšå ±æãããå Žåã¯ã翻蚳ãžã®ãªã³ã¯ã䜿çšããŠãã ããïŒAndrey Karpovã Visual C ++ 2013ã©ã€ãã©ãªã®Sliphodãã§ãã¯ïŒæŽæ°3ïŒ ã
èšäºãèªãã§è³ªåããããŸããïŒ
å€ãã®å Žåãèšäºã«ã¯åã質åãå¯ããããŸãã ããã§ãããã«å¯ŸããåçãåéããŸããïŒ PVS-Studioããã³CppCatããŒãžã§ã³2014ã«é¢ããèšäºã®èªè
ããã®è³ªåãžã®åç ã ãªã¹ããã芧ãã ããã