You are on page 1of 17

. N1.

:
: 09.03.2011

Miranda IM.
, 950
C C++. , ,
.

, .
, Miranda IM,
,
.
Miranda IM PVS-Studio 4.14. Miranda IM
, .
.
Visual Studio Warning Level 3 (/W3), 20%
.

1. memset, memcpy, ZeroMemory

,
, memset, memcpy, ZeroMemory .
. ,
. ,
,
. ,
:
1) . ,
.

2) .
.
. ,
, Miranda.
. , memset/memcpy
. , ,
,
. , Miranda IM.
V512 A call of the 'memcpy' function will lead to a buffer overflow or underflow. tabsrmm utils.cpp 1080
typedef struct _textrangew
{
CHARRANGE chrg;
LPWSTR lpstrText;
} TEXTRANGEW;

const wchar_t* Utils::extractURLFromRichEdit(...)


{
...
::CopyMemory(tr.lpstrText, L"mailto:", 7);
...
}
. ,
. , , 'char'.
Unicode , .
,
, . ,
:
strncpy(tr.lpstrText, "mailto:", 7);
Unicode , 7 :
wcsncpy(tr.lpstrText, L"mailto:", 7);
, . , CopyMemory.
.
V568 It's odd that the argument of sizeof() operator is the '& ImgIndex' expression. clist_modern
modern_extraimage.cpp 302

void ExtraImage_SetAllExtraIcons(HWND hwndList,HANDLE hContact)


{
...
char *(ImgIndex[64]);
...
memset(&ImgIndex,0,sizeof(&ImgIndex));
...
}
, 64-.
. , , .
Copy-Paste:
V568 It's odd that the argument of sizeof() operator is the '& ImgIndex' expression. clist_mw
extraimage.c 295
:
memset(&ImgIndex,0,sizeof(ImgIndex));
, , .
. :
memset(ImgIndex,0,sizeof(ImgIndex));

.
V568 It's odd that the argument of sizeof() operator is the '& rowOptTA' expression. clist_modern
modern_rowtemplateopt.cpp 258

static ROWCELL* rowOptTA[100];

void rowOptAddContainer(HWND htree, HTREEITEM hti)


{
...
ZeroMemory(rowOptTA,sizeof(&rowOptTA));
...
}

, , .
"sizeof(rowOptTA)".
:
const size_t ArraySize = 100;
static ROWCELL* rowOptTA[ArraySize];
...
std::fill(rowOptTA, rowOptTA + ArraySize, nullptr);

, :
V568 It's odd that the argument of sizeof() operator is the '& rowOptTA' expression. clist_modern
modern_rowtemplateopt.cpp 308
V568 It's odd that the argument of sizeof() operator is the '& rowOptTA' expression. clist_modern
modern_rowtemplateopt.cpp 438

, ? , .
, memset.
V512 A call of the 'memset' function will lead to a buffer overflow or underflow. clist_modern
modern_image_array.cpp 59
static BOOL ImageArray_Alloc(LP_IMAGE_ARRAY_DATA iad, int size)
{
...
memset(&iad->nodes[iad->nodes_allocated_size],
(size_grow - iad->nodes_allocated_size) *
sizeof(IMAGE_ARRAY_DATA_NODE),
0);
...
}
.
. , 0 . :
memset(&iad->nodes[iad->nodes_allocated_size], 0,
(size_grow - iad->nodes_allocated_size) *
sizeof(IMAGE_ARRAY_DATA_NODE));

, . ,
, .

, memset ,
OPENFILENAME:
OPENFILENAME x;
memset(&x, 0, sizeof(x));
. :
OPENFILENAME x = { 0 };

2. ,

signed unsigned
. .
, ,
, int unsigned.
, .
. ,
, ,
.
,
. , , ,
. .

V547 Expression 'wParam >= 0' is always true. Unsigned type value is always >= 0. clist_mw
cluiframes.c 3140

id2pos, '-1' .
. id2pos
:
typedef UINT_PTR WPARAM;
static int id2pos(int id);
static int nFramescount=0;

INT_PTR CLUIFrameSetFloat(WPARAM wParam,LPARAM lParam)

{
...
wParam=id2pos(wParam);
if(wParam>=0&&(int)wParam<nFramescount)
if (Frames[wParam].floating)
...
}
, wParam . ,
'wParam>=0' . id2pos '-1',
, .
, :
if (wParam>=0 && wParam<nFramescount)
Visual C++ "warning C4018: '<' : signed/unsigned mismatch".
Warning Level 3, Miranda IM.
.
. , .
:
if ((INT_PTR)wParam>=0 && (INT_PTR)wParam<nFramescount)
. Miranda IM 33 ,
- signed/unsigned .
. . , .

V547 Expression 'nOldLength < 0' is always false. Unsigned type value is never < 0. IRC mstring.h 229

void Append( PCXSTR pszSrc, int nLength )


{
...
UINT nOldLength = GetLength();
if (nOldLength < 0)
{
// protects from underflow
nOldLength = 0;

}
...
}
, .
, .
( WinAPI).

#define SRMSGSET_LIMITNAMESLEN_MIN 0
static INT_PTR CALLBACK DlgProcTabsOptions(...)
{
...
limitLength =
GetDlgItemInt(hwndDlg, IDC_LIMITNAMESLEN, NULL, TRUE) >=
SRMSGSET_LIMITNAMESLEN_MIN ?
GetDlgItemInt(hwndDlg, IDC_LIMITNAMESLEN, NULL, TRUE) :
SRMSGSET_LIMITNAMESLEN_MIN;
...
}
, . ,
. . ,
.
, GetDlgItemInt() 'int', .
UINT. "WinUser.h":
WINUSERAPI
UINT
WINAPI
GetDlgItemInt(
__in HWND hDlg,
__in int nIDDlgItem,
__out_opt BOOL *lpTranslated,
__in BOOL bSigned);

PVS-Studio :
V547 Expression is always true. Unsigned type value is always >= 0. scriver msgoptions.c 458
. "GetDlgItemInt(hwndDlg, IDC_LIMITNAMESLEN, NULL, TRUE) >=
SRMSGSET_LIMITNAMESLEN_MIN" .
, , .
, , . , .

3.
,
. , ,
,
.
, , ,
.
, .
:

V567 Undefined behavior. The 's' variable is modified while being used twice between sequence points.
msn ezxml.c 371
short ezxml_internal_dtd(ezxml_root_t root, char *s, size_t len)
{
...
while (*(n = ++s + strspn(s, EZXML_WS)) && *n != '>') {
...
}
(undefined behavior).
. ,
.
'++s', 'strspn(s, EZXML_WS)'. , ,
, 's'.
, . Miranda IM
/ '&& 0'.
:
if ((1 || altDraw) && ...
if (g_CluiData.bCurrentAlpha==GoalAlpha &&0)
if(checkboxWidth && (subindex==-1 ||1)) {

. ,
. . .
V560 A part of conditional expression is always false: 0. clist_modern modern_clui.cpp 2979

LRESULT CLUI::OnDrawItem( UINT msg, WPARAM wParam, LPARAM lParam )


{
...
DrawState(dis->hDC,NULL,NULL,(LPARAM)hIcon,0,
dis->rcItem.right+dis->rcItem.leftGetSystemMetrics(SM_CXSMICON))/2+dx,
(dis->rcItem.bottom+dis->rcItem.topGetSystemMetrics(SM_CYSMICON))/2+dx,
0,0,
DST_ICON|
(dis->itemState&ODS_INACTIVE&&FALSE?DSS_DISABLED:DSS_NORMAL));
...
}
, FALSE.
? - . ? ,
. . :
UINT uFlags = DST_ICON;
uFlags |= dis->itemState & ODS_INACTIVE && FALSE ?
DSS_DISABLED : DSS_NORMAL;

, , , :
UINT uFlags;
if (dis->itemState & ODS_INACTIVE && (((FALSE))))
uFlags = DST_ICON | DSS_DISABLED;
else
uFlags = DST_ICON | DSS_NORMAL;
, , , FALSE .

4. ,
Copy-Paste.
, .
.
V537 Consider reviewing the correctness of 'maxX' item's usage. clist_modern modern_skinengine.cpp
2898
static BOOL ske_DrawTextEffect(...)
{
...
minX=max(0,minX+mcLeftStart-2);
minY=max(0,minY+mcTopStart-2);
maxX=min((int)width,maxX+mcRightEnd-1);
maxY=min((int)height,maxX+mcBottomEnd-1);
...
}
, . :
minX = max(0,

minX + mcLeftStart - 2);

minY = max(0,

minY + mcTopStart

- 2);

maxX = min((int)width,

maxX + mcRightEnd

- 1);

maxY = min((int)height, maxX + mcBottomEnd - 1);


, , ,
maxX.

. -, . -,
. ,
Miranda IM.
V536 Be advised that the utilized constant value is represented by an octal form. Oct: 037, Dec: 31. msn
msn_mime.cpp 192

static const struct _tag_cpltbl


{
unsigned cp;
const char* mimecp;

} cptbl[] =
{
{

037, "IBM037" },

// IBM EBCDIC US-Canada

437, "IBM437" },

// OEM United States

500, "IBM500" },

// IBM EBCDIC International

708, "ASMO-708" },

// Arabic (ASMO 708)

...
}
, '0',
.
. , . ,
.

5. ,
. ,
.
, . . .
- . :
V525 The code containing the collection of similar blocks. Check items '1316', '1319', '1318', '1323',
'1323', '1317', '1321' in lines 954, 955, 956, 957, 958, 959, 960. clist_modern modern_clcopts.cpp 954

static INT_PTR CALLBACK DlgProcTrayOpts(...)


{
...
EnableWindow(GetDlgItem(hwndDlg,IDC_PRIMARYSTATUS),TRUE);
EnableWindow(GetDlgItem(hwndDlg,IDC_CYCLETIMESPIN),FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_CYCLETIME),FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_ALWAYSPRIMARY),FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_ALWAYSPRIMARY),FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_CYCLE),FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_MULTITRAY),FALSE);
...
}

, .
IDC_ALWAYSPRIMARY. ,
.

6.

,
. , ,
.
, .
- . -
.
- , .
, . ,
, , ,
.
,
:

V560 A part of conditional expression is always true: 0x01000. tabsrmm tools.cpp 1023

#define GC_UNICODE 0x01000

DWORD dwFlags;

UINT CreateGCMenu(...)
{
...
if (iIndex == 1 && si->iType != GCW_SERVER &&
!(si->dwFlags && GC_UNICODE)) {
...
}
. '&' '&&'.
, . :

(si->dwFlags & GC_UNICODE)

.
V528 It is odd that pointer to 'char' type is compared with the '\0' value. Probably meant: *str != '\0'.
clist_modern modern_skinbutton.cpp 282
V528 It is odd that pointer to 'char' type is compared with the '\0' value. Probably meant: *endstr !=
'\0'. clist_modern modern_skinbutton.cpp 283

static char *_skipblank(char * str)


{
char * endstr=str+strlen(str);
while ((*str==' ' || *str=='\t') && str!='\0') str++;
while ((*endstr==' ' || *endstr=='\t') &&
endstr!='\0' && endstr<str)
endstr--;
...
}

'*' .
. access violation. :
while ((*str==' ' || *str=='\t') && *str!='\0') str++;
while ((*endstr==' ' || *endstr=='\t') &&
*endstr!='\0' && endstr<str)
endstr--;
,
.

.
V514 Dividing sizeof a pointer 'sizeof (text)' by another value. There is a probability of logical error
presence. clist_modern modern_cachefuncs.cpp 567

#define SIZEOF(X) (sizeof(X)/sizeof(X[0]))

int Cache_GetLineText(..., LPTSTR text, int text_size, ...)


{
...
tmi.printDateTime(pdnce->hTimeZone, _T("t"), text, SIZEOF(text), 0);
...
}

. ,
SIZEOF. COUNT_OF, . ,
. "sizeof(LPTSTR) /
sizeof(TCHAR)". ,
. :
tmi.printDateTime(pdnce->hTimeZone, _T("t"), text, text_size, 0);


V560 A part of conditional expression is always true: 0x29. icqoscar8 fam_03buddy.cpp 632

void CIcqProto::handleUserOffline(BYTE *buf, WORD wLen)


{
...
else if (wTLVType = 0x29 && wTLVLen == sizeof(DWORD))
...
}

.
:
if (0x29 = wTLVType && sizeof(DWORD) == wTLVLen)
, , . ,
, , ,
.

,
/, .
, , , .
Miranda IM, PVS-Studio V559:
else if (ft->ft_magic = FT_MAGIC_OSCAR)
if (ret=0) {return (0);}
if (Drawing->type=CLCIT_CONTACT)

, .
, Miranda IM .
, . ,
:
V542 Consider inspecting an odd type cast: 'char *' to 'char'. clist_modern modern_toolbar.cpp 586

static void
sttRegisterToolBarButton(..., char * pszButtonName, ...)
{
...
if ((BYTE)pszButtonName)
tbb.tbbFlags=TBBF_FLEXSIZESEPARATOR;
else
tbb.tbbFlags=TBBF_ISSEPARATOR;
...
}
, 256. ,
. , , .

. :
V501 There are identical sub-expressions 'user->statusMessage' to the left and to the right of the '&&'
operator. jabber jabber_chat.cpp 214

void CJabberProto::GcLogShowInformation(...)

{
...
if (user->statusMessage && user->statusMessage)
...
}

. , .
,
.
,
. . ,
, , .
,
.
-. ,
. ,
';' 'for'.
, 10 .

,
++. ,
.

P.S.
, , - ,
/ . ,
Miranda IM.
, . .
, . , , ,
, . ,
Miranda IM PVS-Studio.
, , .
, .
:
V523 The 'then' statement is equivalent to the 'else' statement. scriver msglog.c 695
if ( streamData->isFirst ) {

if (event->dwFlags & IEEDF_RTL) {


AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\rtlpar");
} else {
AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\ltrpar");
}
} else {
if (event->dwFlags & IEEDF_RTL) {
AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\rtlpar");
} else {
AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\ltrpar");
}
}
. , . ,
. ,
. ,
.