You are on page 1of 10

. N3.

:
: 07.07.2011

, ,
.
[1] [2]. Qt.

Qt 4.7.3. . PVS-Studio
, - , ,
Qt. .
, , . ,
, .
, . :
if (strcmp(My_Str_A, My_Str_A) == 0)
. . ,
strcmp(). .
. Qt - qstrcmp(). ,
, :
if (qstrcmp(My_Str_A, My_Str_A) == 0)
Qt -
. .
,
, , , .

1. ,

Qt .
,
.
:
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);
...
}
. ,
. :
void QXmlStreamReaderPrivate::init()
{
tos = 0;

<<<===

scanDtd = false;
token = -1;
token_char = 0;
isEmptyElement = false;
isWhitespace = true;

isCDATA = false;
standalone = false;
tos = 0;

<<<===

...
}
, .
. -
, , . , ,
- .
:
1. . ,
.
2. ,
.
, "tos = 1" (. ),
, - "tos" .
3. . ,
- .
, , . ? ,
/ . .
,
. :
struct T {
int x, y, z;
float m;
int q, w, e, r, t;
} A;
...
A.m = 0.0;
A.q = 0;
A.x = 0;
A.y = 0;
A.z = 0;
A.q = 0;

A.w = 0;
A.r = 1;
A.e = 1;
A.t = 1;
, . ,
, .
'q'. ,
. ,
, . :
struct T {
int x, y, z;
float m;
int q, w, e, r, t;
} A;
...
A.x = 0;
A.y = 0;
A.z = 0;
A.m = 0.0;
A.q = 0;
A.w = 0;
A.e = 1;
A.r = 1;
A.t = 1;
, ,
. . ,
.
. , ,
, .

2. - .
. " "
N18 [3]:

, ,
, if case. ,
, , .
.
.
, , - switch()
if-else. . , - "case:"
"if" . .
. , Qt.
int QCleanlooksStyle::pixelMetric(...)
{
int ret = -1;
switch (metric) {
...
case PM_SpinBoxFrameWidth:
ret = 3;
break;
case PM_MenuBarItemSpacing:
ret = 6;
case PM_MenuBarHMargin:
ret = 0;
break;
...
}
- switch(). , , "break".
, "ret"
.
, , - std::map<PixelMetric, int>
.
.
:
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");
...
}
'ver' WV_2000. ,
. , :
struct {
QSysInfo::WinVersion; m_ver;
const char *m_str;
} Table_WinVersionToString[] = {
{ WV_Me,

"WinMe" },

{ WV_95,

"Win95" },

{ WV_98,

"Win98" },

{ WV_NT,

"WinNT" },

{ WV_2000, "Win2000" },
{ WV_2003, "Win2003" },
{ WV_XP,

"WinXP" },

{ WV_VISTA,"WinVista" }
};

ret = QLatin1String("Unknown");
for (size_t i = 0; i != count_of(Table_WinVersionToString); ++i)
if (Table_WinVersionToString[i].m_ver == ver)
ret = QLatin1String(Table_WinVersionToString[i].m_str);

, , .
, .
. . ,
, .
, .

3.
Qt , , ,
. . *.cpp, *.h
Qt 250 . ,
. , Qt,
- . , .
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

...
}
&& &. ,
. ,
.
:
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". , .
, . ?
PVS-Studio? , . .
.
:
PassRefPtr<Structure>
Structure::getterSetterTransition(Structure* structure)
{
...
RefPtr<Structure> 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;
...
}
, .
"transition->m_hasGetterSetterProperties".

, , , :
const char *p = ...;
if (p == "12345")

, ,
strcmp(). , ++ ,
, :
const TCHAR* getQueryName() const;
...
Query* MultiFieldQueryParser::parse(...)
{
...
if (q && (q->getQueryName() != _T("BooleanQuery") ...
...
}
. , , .
bool qt_testCollision(...)
{
...
t=x1; x1=x2; x2=t;
t=y1; x1=y2; y2=t;
...
}
, . ,
. :
bool equals( class1* val1, class2* val2 ) const
{
...
size_t size = val1->size();
...
while ( --size >= 0 ){
if ( !comp(*itr1,*itr2) )
return false;
itr1++;
itr2++;

}
...
}
"--size >= 0" , size .
, .
. , ,
. ,
:
STDMETHODIMP QEnumPins::QueryInterface(const IID &iid,void **out)
{
...
if (S_OK)
AddRef();
return hr;
}
- "if (hr == S_OK)" "if (SUCCEEDED(hr))". S_OK
, 0. .


. ,
, .
, ,
,
.


1. . . N1.
http://www.viva64.com/ru/a/0070/
2. . . N2.
http://www.viva64.com/ru/a/0072/
3. . . - / . . - . : -
" " ; . : , 2005. - 896 . : .