Вы находитесь на странице: 1из 16

Visual

C++ 2012
:
: 19.09.2012
. ,
. Visual Studio,
.
. ,
, PVSStudio /++/++11.

Visual Studio .
. , Visual Studio
. ,
.
Visual Assist. ,
Adobe Photoshop CorelDRAW.
.
. . ,
PVS-Studio Visual Studio 2012.
, , Visual Studio.
. Visual Studio 2012 ++11,
. , PVS-Studio
.
, *.h .
, Visual Studio 2012. :

Program Files (x86)\Microsoft Visual Studio 11.0\VC\include


Program Files (x86)\Microsoft Visual Studio 11.0\VC\crt
Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc

, make-
. , .
, .

, PVS-Studio Visual C++. ,


, Visual C++.


, .
PVS-Studio ,
.


.
.
template <class T>
class ATL_NO_VTABLE CUtlProps :
public CUtlPropsBase
{
....
HRESULT GetIndexOfPropertyInSet(....)
{
....
for(ULONG ul=0; ul<m_pUPropSet[*piCurSet].cUPropInfo; ul++)
{
if( dwPropertyId == pUPropInfo[ul].dwPropId )
*piCurPropId = ul;
return S_OK;
}

return S_FALSE;
}
....
};
V612 An unconditional 'return' within a loop. atldb.h 4829

. . ,
'return' , .
:
for(ULONG ul=0; ul<m_pUPropSet[*piCurSet].cUPropInfo; ul++)
{
if( dwPropertyId == pUPropInfo[ul].dwPropId )
{
*piCurPropId = ul;
return S_OK;
}
}


.
.
// TEMPLATE FUNCTION proj
_TMPLT(_Ty) inline
_CMPLX(_Ty) proj(const _CMPLX(_Ty)& _Left)
{

// return complex projection

return (_CMPLX(_Ty)(
_CTR(_Ty)::_Isinf(real(_Left)) ||
_CTR(_Ty)::_Isinf(real(_Left))
? _CTR(_Ty)::_Infv(real(_Left)) : real(_Left),
imag(_Left) < 0 ? -(_Ty)0 : (_Ty)0));
}
V501 There are identical sub-expressions '_Ctraits < _Ty >::_Isinf(real(_Left))' to the left and to the right of
the '||' operator. xcomplex 780
"_CTR(_Ty)::_Isinf(real(_Left))". ,
. .


template<typename BaseType, bool t_bMFCDLL = false>

class CSimpleStringT
{
....
void Append(_In_reads_(nLength) PCXSTR pszSrc,
_In_ int nLength)
{
....
UINT nOldLength = GetLength();
if (nOldLength < 0)
{
// protects from underflow
nOldLength = 0;
}
....
};
V547 Expression 'nOldLength < 0' is always false. Unsigned type value is never < 0. atlsimpstr.h 420
. , .
CSimpleStringT . , nOldLength
, . . .


template <class T>
class CHtmlEditCtrlBase
{
....
HRESULT SetDefaultComposeSettings(
LPCSTR szFontName=NULL, .....) const
{
CString strBuffer;
....

strBuffer.Format(_T("%d,%d,%d,%d,%s,%s,%s"),
bBold ? 1 : 0,
bItalic ? 1 : 0,
bUnderline ? 1 : 0,
nFontSize,
szFontColor,
szBgColor,
szFontName);
....
}
};
V576 Incorrect format. Consider checking the eighth actual argument of the 'Format' function. The pointer
to string of wchar_t type symbols is expected. afxhtml.h 826
UNICODE . 'Format()' ,
LPCTSTR. 'szFontName' LPCSTR.


typedef WORD ATL_URL_PORT;
class CUrl
{
ATL_URL_PORT m_nPortNumber;
....
inline BOOL Parse(_In_z_ LPCTSTR lpszUrl)
{
....
//get the port number
m_nPortNumber = (ATL_URL_PORT) _ttoi(tmpBuf);
if (m_nPortNumber < 0)
goto error;
....

};
V547 Expression 'm_nPortNumber < 0' is always false. Unsigned type value is never < 0. atlutil.h 2775
, , . 'm_nPortNumber'
' WORD'. 'WORD' 'unsigned short'.


Visual C++ .
#define DXVABitMask(__n) (~((~0) << __n))
, . , Visual C++
, . , , Visual C++
. ,
Undefined behavior. " ,
. ".

64-
64-
64- /++. , ,
12.
class CWnd : public CCmdTarget
{
....
virtual void WinHelp(DWORD_PTR dwData,
UINT nCmd = HELP_CONTEXT);
....
};

class CFrameWnd : public CWnd


{
....
};

class CFrameWndEx : public CFrameWnd


{

....
virtual void WinHelp(DWORD dwData,
UINT nCmd = HELP_CONTEXT);
....
};
V301 Unexpected function overloading behavior. See first argument of function 'WinHelpW' in derived class
'CFrameWndEx' and base class 'CFrameWnd'. afxframewndex.h 154
'WinHelp' 'CFrameWndEx' .
'DWORD_PTR'. :

V301 Unexpected function overloading behavior. See first argument of function 'WinHelpW' in
derived class 'CMDIFrameWndEx' and base class 'CFrameWnd'. afxmdiframewndex.h 237
V301 Unexpected function overloading behavior. See first argument of function 'WinHelpW' in
derived class 'CMDIFrameWndEx' and base class 'CMDIFrameWnd'. afxmdiframewndex.h 237
V301 Unexpected function overloading behavior. See first argument of function 'WinHelpW' in
derived class 'COleIPFrameWndEx' and base class 'CFrameWnd'. afxoleipframewndex.h 130
V301 Unexpected function overloading behavior. See first argument of function 'WinHelpW' in
derived class 'COleIPFrameWndEx' and base class 'COleIPFrameWnd'. afxoleipframewndex.h 130
V301 Unexpected function overloading behavior. See first argument of function 'WinHelpW' in
derived class 'COleDocIPFrameWndEx' and base class 'CFrameWnd'. afxoledocipframewndex.h 129
V301 Unexpected function overloading behavior. See first argument of function 'WinHelpW' in
derived class 'COleDocIPFrameWndEx' and base class 'COleIPFrameWnd'. afxoledocipframewndex.h
129
V301 Unexpected function overloading behavior. See first argument of function 'WinHelpW' in
derived class 'COleDocIPFrameWndEx' and base class 'COleDocIPFrameWnd'.
afxoledocipframewndex.h 129

, NULL
. ,
, . .
.
BOOL CDockablePane::PreTranslateMessage(MSG* pMsg)
{
....
CBaseTabbedPane* pParentBar = GetParentTabbedPane();
CPaneFrameWnd* pParentMiniFrame =
pParentBar->GetParentMiniFrame();

if (pParentBar != NULL &&


(pParentBar->IsTracked() ||
pParentMiniFrame != NULL &&
pParentMiniFrame->IsCaptured()
)
)
....
}
V595 The 'pParentBar' pointer was utilized before it was verified against nullptr. Check lines: 2840, 2841.
afxdockablepane.cpp 2840
, 'pParentBar' GetParentMiniFrame().
, NULL
.
AFX_CS_STATUS CDockingManager::DeterminePaneAndStatus(....)
{
....
CDockablePane* pDockingBar =
DYNAMIC_DOWNCAST(CDockablePane, *ppTargetBar);

if (!pDockingBar->IsFloating() &&
(pDockingBar->GetCurrentAlignment() &
dwEnabledAlignment) == 0)
{
return CS_NOTHING;
}
if (pDockingBar != NULL)
{
return pDockingBar->GetDockingStatus(
pt, nSensitivity);

}
....
}
V595 The 'pDockingBar' pointer was utilized before it was verified against nullptr. Check lines: 582, 587.
afxdockingmanager.cpp 582
'pDockingBar' , NULL.

:
void CFrameImpl::AddDefaultButtonsToCustomizePane(....)
{
....
for (POSITION posCurr = lstOrigButtons.GetHeadPosition();
posCurr != NULL; i++)
{
CMFCToolBarButton* pButtonCurr =
(CMFCToolBarButton*)lstOrigButtons.GetNext(posCurr);

UINT uiID = pButtonCurr->m_nID;

if ((pButtonCurr == NULL) ||
(pButtonCurr->m_nStyle & TBBS_SEPARATOR) ||
(....)
{
continue;
}
....
}

V595 The 'pButtonCurr' pointer was utilized before it was verified against nullptr. Check lines: 1412, 1414.
afxframeimpl.cpp 1412
'm_nID'. , 'pButtonCurr'
0.


CString m_strBrowseFolderTitle;

void CMFCEditBrowseCtrl::OnBrowse()
{
....
LPCTSTR lpszTitle = m_strBrowseFolderTitle != _T("") ?
m_strBrowseFolderTitle : (LPCTSTR)NULL;
....
}
V623 Consider inspecting the '?:' operator. A temporary object is being created and subsequently
destroyed. afxeditbrowsectrl.cpp 308
. , "(LPCTSTR)NULL"
CString.
. , CString .
'lpszTitle' .
.


UINT CMFCPopupMenuBar::m_uiPopupTimerDelay = (UINT) -1;
....
void CMFCPopupMenuBar::OnChangeHot(int iHot)
{
....
SetTimer(AFX_TIMER_ID_MENUBAR_REMOVE,
max(0, m_uiPopupTimerDelay - 1),
NULL);
....

}
V547 Expression '(0) > (m_uiPopupTimerDelay - 1)' is always false. Unsigned type value is never < 0.
afxpopupmenubar.cpp 968
'-1' . 'max'
m_uiPopupTimerDelay. ,
. .
:
SetTimer(AFX_TIMER_ID_MENUBAR_REMOVE,
m_uiPopupTimerDelay == (UINT)-1 ? 0 : m_uiPopupTimerDelay - 1,
NULL);
:

V547 Expression '(0) > (m_uiPopupTimerDelay - 1)' is always false. Unsigned type value is never < 0.
afxribbonpanelmenu.cpp 880


BOOL CMFCTasksPaneTask::SetACCData(CWnd* pParent, CAccessibilityData&
data)
{
....
data.m_nAccHit = 1;
data.m_strAccDefAction = _T("Press");
data.m_rectAccLocation = m_rect;
pParent->ClientToScreen(&data.m_rectAccLocation);
data.m_ptAccHit;
return TRUE;
}
V607 Ownerless expression 'data.m_ptAccHit'. afxtaskspane.cpp 96
"data.m_ptAccHit;" ? -
?

0?
BOOL CMFCTasksPane::GetMRUFileName(....)
{

....
const int MAX_NAME_LEN = 512;

TCHAR lpcszBuffer [MAX_NAME_LEN + 1];


memset(lpcszBuffer, 0, MAX_NAME_LEN * sizeof(TCHAR));

if (GetFileTitle((*pRecentFileList)[nIndex],
lpcszBuffer, MAX_NAME_LEN) == 0)
{
strName = lpcszBuffer;
return TRUE;
}
....
}
V512 A call of the 'memset' function will lead to underflow of the buffer 'lpcszBuffer'. afxtaskspane.cpp
2626
, ,
. , :
memset(lpcszBuffer, 0, (MAX_NAME_LEN + 1) * sizeof(TCHAR));

'if'
void CMFCVisualManagerOfficeXP::OnDrawBarGripper(....)
{
....
if (bHorz)
{
rectFill.DeflateRect(4, 0);
}
else
{

rectFill.DeflateRect(4, 0);
}
....
}
V523 The 'then' statement is equivalent to the 'else' statement. afxvisualmanagerofficexp.cpp 264

single_link_registry
'single_link_registry' ,
.
'single_link_registry':
virtual ~single_link_registry()
{
// It is an error to delete link registry with links
// still present
if (count() != 0)
{
throw invalid_operation(
"Deleting link registry before removing all the links");
}
}
V509 The 'throw' operator inside the destructor should be placed within the try..catch block. Raising
exception inside the destructor is illegal. agents.h 759
. .
, .
'single_link_registry' , .
. C++ ,
terminate().
:

V509 The 'throw' operator inside the destructor should be placed within the try..catch block. Raising
exception inside the destructor is illegal. concrt.h 4747
V509 The 'throw' operator inside the destructor should be placed within the try..catch block. Raising
exception inside the destructor is illegal. agents.h 934

V509 The 'throw' operator inside the destructor should be placed within the try..catch block. Raising
exception inside the destructor is illegal. taskcollection.cpp 880


void CPreviewView::OnPreviewClose()
{
....
while (m_pToolBar && m_pToolBar->m_pInPlaceOwner)
{
COleIPFrameWnd *pInPlaceFrame =
DYNAMIC_DOWNCAST(COleIPFrameWnd, pParent);
if (!pInPlaceFrame)
break;

CDocument *pViewDoc = GetDocument();


if (!pViewDoc)
break;
// in place items must have a server document.
COleServerDoc *pDoc =
DYNAMIC_DOWNCAST(COleServerDoc, pViewDoc);
if (!pDoc)
break;
// destroy our toolbar
m_pToolBar->DestroyWindow();
m_pToolBar = NULL;
pInPlaceFrame->SetPreviewMode(FALSE);
// restore toolbars
pDoc->OnDocWindowActivate(TRUE);

break;
}
....
}
V612 An unconditional 'break' within a loop. viewprev.cpp 476
'continue'. 'break'. .
. 'while' 'if'.


, .
, , .
afxdrawmanager.cpp :
const double AFX_PI = 3.1415926;
V624 The constant 3.1415926 is being utilized. The resulting value could be inaccurate. Consider using the
M_PI constant from <math.h>. afxdrawmanager.cpp 22
. , -
M_PI, :
#define M_PI 3.14159265358979323846

Visual C++
, make- , Visual C++.
. - .
, :).
, PVS-Studio .
, make-.
, , .

, Visual Studio 2012 /++ . ,


. .
. - PVSStudio. . .
, , .
Visual C++, .
Clang, .

. Visual Studio 2005, 2008, 2010, 2012


.
PVS-Studio : http://www.viva64.com/ru/pvs-studio/.

Вам также может понравиться