ãããžã§ã¯ãã®æºå
ãã¹ã¿ãžãªãã«å ªèœã§ãQtãããžã§ã¯ãã®éçºæ¹æ³ãé·ãéåŠãã§ããå Žåã¯ããã®ã»ã¯ã·ã§ã³ãã¹ãããããŠãã ããã VS2010ã®ãããžã§ã¯ããæºåããç§ã®æ¹æ³ã¯æ¬¡ã®ãšããã§ãã
Qtãã¬ãŒã ã¯ãŒã¯ã«åºã¥ããŠããã°ã©ã ãéçºããŠããããããããžã§ã¯ãã«.proãã¡ã€ã«ããããŸãã ãã®ãã¡ã€ã«ã¯ããããžã§ã¯ããçæããããã®åºç€ã§ãã Qt Webãµã€ãïŒ http://doc.qt.nokia.com/stable/qmake-project-files.html ïŒã«ã¯ãqmakeã䜿çšããŠãã¹ã¿ãžãªããããžã§ã¯ããçæã§ãããšèšèŒãããŠããŸãã ãããè¡ãã«ã¯ã次ã®ã³ãã³ãã䜿çšããŸãã
$ {QTDIR} \ bin \ qmake.exe -t vcapp -spec $ {QTDIR} \ mkspecs \ win32-msvc2010
次ã«ããããžã§ã¯ããã¡ã€ã«* .vcxprojã衚瀺ãããŸããããã¯ããã¹ã¿ãžãªãã«ãã£ãŠéãããŸãã ãã以äžã®æäœã¯å¿ èŠãããŸããã§ãã-ãããžã§ã¯ãã¯æ£åžžã«ã³ã³ãã€ã«ãããŸããã
PVS-Studioã®ã€ã³ã¹ããŒã«ãšæ§æ
ã€ã³ã¹ããŒã«ã¯äžå¯èœã§ããããŠã³ããŒããã€ã³ã¹ããŒã«ãåèµ·åãããšãã¡ãã¥ãŒã«ç®çã®ã¿ã-PVS-Studioããã§ã«ãããŸãã ç§ã¯ã»ããã¢ããã«å°ãæãå ããªããã°ãªããŸããã§ããã ç§ãç¥ããªãçç±ã§ããããžã§ã¯ããåæãããšãïŒPVS-Studio->ãœãªã¥ãŒã·ã§ã³ã®ãã§ãã¯ïŒãPVSã¯QtããããŒãã¡ã€ã«ïŒQWidget.hãQObject.hãªã©ïŒãèŠã€ããããšãã§ããŸãããããããžã§ã¯ãã¯ãšã©ãŒãªãã§ã³ã³ãã€ã«ãããŸãã ãã®ç¶æ³ãä¿®æ£ããã«ã¯ããããžã§ã¯ãèšå®ã«ç§»åãïŒãããžã§ã¯ããå³ã¯ãªãã¯->ããããã£ïŒããVC ++ãã£ã¬ã¯ããªããéžæããããã£ã¬ã¯ããªãå«ãããã»ã¯ã·ã§ã³ã§QtããããŒãã¡ã€ã«ãžã®ãã¹ãæå®ããŸãã ããã«ãQt \ includeã®ã«ãŒããã©ã«ããŒã ãã§ãªãã䜿çšããã¢ãžã¥ã©ãŒãµããã©ã«ããŒãå«ããå¿ èŠããããŸãã ã€ãŸãããããžã§ã¯ããã³ã¢ãguiãxmlãsqlãnetworkãwebkitãopenglã¢ãžã¥ãŒã«ã䜿çšããŠããããšã.proãã¡ã€ã«ã瀺ããŠããå Žåã¯ãincludeãinclude \ qtcoreãinclide \ qtguiãincludeãè¿œå ããå¿ èŠããããŸã\ qtxmlãã€ã³ã¯ã«ãŒã\ qtxmlpatternsãã€ã³ã¯ã«ãŒã\ qtsqlãã€ã³ã¯ã«ãŒã\ qtnetworkãã€ã³ã¯ã«ãŒã\ qtwebkitãã€ã³ã¯ã«ãŒã\ qtopenglã ãããã®ã¢ã¯ã·ã§ã³ãå®è£ ãããšãPVS-Studioã¯æ£åžžã«åäœãå§ããŸãã
éç解æ
åæã«ã¯çŽ4æéãããããã®æç¹ã§ã¹ããŒããŒããããŠããŸããã ããã§ãããã¯çºèŠãããŸããïŒ
- 120ã«ããŽãª1ã¢ã©ãŒã
- 164ã«ããŽãª2ã®èŠå
- 287ã«ããŽãª3ã®èŠå
ãã®ã«ããŽãªã§ã¯ã æ倧 250件 ïŒå šäœã®87 %% ïŒã®èŠåãV001ã 'file'ã®ã³ãŒããã©ã°ã¡ã³ããåæã§ããŸãã '' ãPVSãç¹å®ã®ãã¡ã€ã«ã®è§£æã«å€±æããããšãå ±åããŠããŸãã å€ãã®èŠåã¯ãmoc * .cppãªã©ã®èªåçæãã¡ã€ã«ãåç §ããŠããŸãã PVSããããã®ãã¡ã€ã«ã解æããããšããªãå Žåãç§ã«ãšã£ãŠã¯ãã䟿å©ã§ãã
次ã«äººæ°ã®ããèŠåã¯ãV550ã å¥åŠãªæ£ç¢ºãªæ¯èŒã å®çŸ©ããã粟床ãšã®æ¯èŒã䜿çšããããšããå§ãããŸãïŒfabsïŒA-BïŒ<EpsilonãŸãã¯fabsïŒA-BïŒ> Epsilon ã ã èŠåã®åæã«ããã 8ã€ã®åœéœæ§ãš1 ã€ã®åœéœæ§ã瀺ãããŸããã
ãã®ãããã¯ã«ã¯æ¬¡ã®èŠåããããŸãã ã¿ã€ã 'long'ã®ãµã€ãºã¯LLP64 / LP64ããŒã¿ã¢ãã«éã§ç°ãªãããšã«æ³šæããŠãã ãã '' ïŒ
ãã®èšºæã¡ãã»ãŒãžã«ãããããã°ã©ã ã§äœ¿çšãããŠãããã¹ãŠã®ãé·ããã¿ã€ããèŠã€ããããšãã§ããŸããç§ã¯Qtãã¬ãŒã ã¯ãŒã¯ã䜿çšããŠããã®ã§ãlongåã䜿çšããããšã¯äžè¬çã«å£èª¿ãæªãããšãæãåºãããŠãã ãããã¯ãã¹ãã©ãããã©ãŒã éçºã«ã¯qint16ãqint32ããã³qint64ã䜿çšããå¿ èŠããããŸãã å¯äžã®åé¡ã¯ããã®å Žåã®PVSã®äœ¿çšããããžã§ã¯ãå šäœã®æ€çŽ¢ãããåªããŠããããšã§ãã çµå±ã®ãšããããããã®èŠåã¯ææ補åã§ããViva64ã«é©çšãããŸãã ãããã®èŠåã§ã¯ã³ãŒãèŠåã¯ç¡å¹ã«ãªã£ãŠããŸãïŒç解ãšç·šéãéåžžã«å°é£ã«ãªããŸãïŒã
ãã¡ãããããã°ã©ã ã«ãlongãåãååšããããšèªäœã¯ãšã©ãŒã§ã¯ãããŸããã ãã ããWindowsããã³Linuxã§æ£åžžã«åäœããå¿ èŠããã移æ€å¯èœãª64ãããã³ãŒããäœæããå Žåããã®ã¿ã€ãã䜿çšãããŠããããã°ã©ã ããã¹ãã®ãã¹ãŠã®ãã©ã°ã¡ã³ãã確èªããå¿ èŠããããŸãã
WindowsãšLinuxã¯ã64ãããã¢ãŒããã¯ãã£çšã«ç°ãªãããŒã¿ã¢ãã«ã䜿çšããŸãã ããŒã¿ã¢ãã«ãšã¯ãintãfloatãpointerãªã©ã®åºæ¬ããŒã¿åã®ãµã€ãºã®çžé¢ãæå³ããŸãã Windowsã¯LLP64ããŒã¿ã¢ãã«ã䜿çšããLinuxã¯LP64ããŒã¿ã¢ãã«ã䜿çšããŸãã ãããã®ã¢ãã«ã§ã¯ããlongãã¿ã€ãã®ãµã€ãºãç°ãªããŸãã
WindowsïŒLLP64ïŒã§ã¯ããlongãã¿ã€ãã®ãµã€ãºã¯4ãã€ãã§ãã
LinuxïŒLP64ïŒã§ã¯ããlongãã¿ã€ãã®ãµã€ãºã¯8ãã€ãã§ãã
ãlongãã¿ã€ãã®ãµã€ãºã®éãã«ããããã¡ã€ã«åœ¢åŒãäºææ§ããªããªã£ãããLinuxããã³Windowsã§å®è¡ãããã³ãŒããéçºãããšãã«ãšã©ãŒãçºçãããããå ŽåããããŸãã å¿ èŠã«å¿ããŠãPVS-Studioã䜿çšããŠã 'long'ã¿ã€ãã䜿çšãããŠãããã¹ãŠã®ã³ãŒããã©ã°ã¡ã³ãã確èªã§ããŸãã
ããã°ã©ã ã®ãã©ã€ã¢ã«ã®ããã«åæã§ããªãã£ããšããèŠåïŒ
ãV111ã å¯å€æ°ã®åŒæ°ã§é¢æ° 'foo'ãåŒã³åºããŸãã NåŒæ°ã®ãµã€ãºã¯memsizeã§ãâ
ã«ããŽãªãŒ2
ãã®ã«ããŽãªã«ã¯æ鬱ãªç¶æ³ããããŸãããäžè¬åæïŒç¡æåæïŒã«é¢é£ããèŠå-4åïŒå šäœã®2ïŒ ïŒãšViva64ããã®160åã®è©ŠéšèŠåã§ãã
é説çã«ãè©ŠéšçãªèŠåã®å€§éšåã¯ãV112ã å±éºãªéæ³ã®æ°Nã䜿çšãããŸããããããã«ããŽãª3ã«ãããŸããååãšããŠãPVSãã«ããŽãª2ã«å±ããã«ããŽãª3ã«ããéšåã¯è¬ã§ãã 倧ãŸããªæ€æ»ã§çŽ90ïŒ ã®èª€æ€åºã瀺ãããããããã®èŠåã®ã¢ãã©ã€ã¶ãŒãæ¹åããå¿ èŠããããšèããŠããŸãã çã®å¿çã1ã€ãèŠã€ãããªãã£ããšããèšããŸãã ããããç§ã¯ãµã³ãã«å šäœããã§ãã¯ããŸããã§ããããªããªããè©Šè¡é¯èª€ãããªãã¯ãããããã§ã-ç§ã¯ç²ããŠããŸãã ãã®èŠåã«ãããšãããžãã¯ãã³ããŒã¯äž»ã«ãããŸããŸãªã€ã³ãã³ããšãªãã»ããã®èšå®ãªã©ã®æç»æé ã§èŠã€ãããŸããã
ç¡æã¢ã¯ã»ã¹ã¢ã©ãŒãïŒ
ãV537ã 'X'ã¢ã€ãã ã®äœ¿çšæ³ã®æ£ç¢ºãã確èªããããšãæ€èšããŠãã ãã '' ïŒ
ã¢ãã©ã€ã¶ãŒã¯ãã³ãŒãã®æœåšçãªãã¹ããªã³ããæ€åºããŸããã ãã®ã«ãŒã«ã¯ãçºèŠçæ¹æ³ã䜿çšããŠã次ã®ã¿ã€ãã®ãšã©ãŒã蚺æããããšããŸãã-誀æ€ç¥ã ã³ãŒãã¯æ¬¡ã®ãšããã§ãã
int x = static_cast <int>ïŒGetXïŒïŒïŒ* n;
int y = static_cast <int>ïŒGetXïŒïŒïŒ* n;
2è¡ç®ã§ã¯ãGetYïŒïŒã®ä»£ããã«GetXïŒïŒé¢æ°ã䜿çšãããŸãã ããã¯æ£ããã³ãŒãã§ãïŒ
int x = static_cast <int>ïŒGetXïŒïŒïŒ* n;
int y = static_cast <int>ïŒGetYïŒïŒïŒ* n;
int width = img_in->width();
int height = img_in->height();
if (width > height) {
if (width > maxWidth) {
height = ( int ) (( float ) maxWidth / width * height);
width = maxWidth;
}
} else {
if (height > maxHeight) {
/**/ width = ( int ) (( float ) maxHeight / height * width);
height = maxHeight;
}
}
* This source code was highlighted with Source Code Highlighter .
ãV525ã åæ§ã®ãããã¯ã®ã³ã¬ã¯ã·ã§ã³ãå«ãã³ãŒãã è¡N1ãN2ãN3ãâŠã®é ç®XãYãZã...ããã§ãã¯ããŸã -誀æ€ç¥ã
ææã¢ã¯ã»ã¹èŠåïŒ
ãV401ã æ§é äœã®ãµã€ãºã¯ããã£ãŒã«ãã®é åºãå€æŽããããšã§å°ããã§ããŸãã ãµã€ãºãNãã€ãããKãã€ãã«æžããããšãã§ããŸã ã
ã¢ãã©ã€ã¶ãŒã¯ãã¡ã€ã³ã¡ã¢ãªã®ç¡å¹ãªäœ¿çšã«ã€ãªããå¯èœæ§ã®ããããŒã¿æ§é ãæ€åºããŸãããçŸæç¹ã§ã¯ããããã©ã®ããã«å¯èœããç解ããããšã¯ã§ããŸãããããããçå®ã§ããã°ãããã¯çŽ æŽãããããšã§ãããã®èŠåã¯ç§ã«ãšã£ãŠéåžžã«åœ¹ç«ã¡ãŸããããããšãã
Viva64ãç¡å¹ãã¢ããŠã³ã¹ããæ§é ã®äŸãèããŠã¿ãŸãããã
struct LiseElement {
bool m_isActive;
char * m_pNext;
int m_value;
};
ãã®æ§é ã¯ãããŒã¿ã®èª¿æŽã«é¢é£ãã64ãããã³ãŒãã§24ãã€ããå æããŸãã ãã ãããã£ãŒã«ãã®é åºãå€æŽãããšããã®ãµã€ãºã¯16ãã€ããå æããŸãã æ§é ã®æé©åãããããªã¢ã³ãã¯æ¬¡ã®ããã«ãªããŸãã
struct LiseElement {
char * m_pNext;
int m_value;
bool m_isActive;
};
...
ã«ããŽãªãŒ1
ç¶æ³ã¯ã«ããŽãªãŒ2ã«äŒŒãŠããŸãïŒ 1ã€ã®ç¡æèŠåãš119ã®æ¯æãã®ã¿ã
ç¡æã®èŠåïŒ
ãV524ã ãFoo_1ãé¢æ°ããFoo_2ãé¢æ°ãšå®å šã«åçã§ããããšã¯å¥åŠã§ã -誀æ€ç¥ ïŒ
const qrealïŒgetXïŒïŒconst {
throw std :: runtime_errorïŒ "ãµããŒããããŠããªãæäœãšã©ãŒ"ïŒ;
}
const qrealïŒgetYïŒïŒconst {
throw std :: runtime_errorïŒ "ãµããŒããããŠããªãæäœãšã©ãŒ"ïŒ;
}
ææã®èŠåïŒ
ãV103ã memsizeåãã32ãããåãžã®æé»çãªåå€æã
ãV104ã ç®è¡åŒã®memsizeåãžã®æé»çãªåå€æã
ãV110ã memsizeåãã32ãããåãžã®æ»ãå€ã®æé»çãªåå€æã
ãV302ã 'foo'ã¯ã©ã¹ã®ã¡ã³ããŒæŒç®å[]ã«ã¯ã32ãããåã®åŒæ°ããããŸãã ããã§memsize-typeã䜿çšããŸã -ãããã®èŠåã¯QtãœãŒã¹ã³ãŒããç¹ã«qtessolator.cppãã¡ã€ã«ã§èŠã€ãããŸããã çå®ã¯ãè©Šè¡é¯èª€ã®ããã«æ€èšŒã§ããŸããã§ããã
äžéšã®ãšã©ãŒãç¹ã«V114ã§ã¯ãPVS-Studio V121ã¯èŠåãè€è£œããŸãã ãã®ãããèŠåã®ãªã¹ãã«ã¯ãåãè¡ãåç §ããåãã¿ã€ãã®èŠåã®å¹³å4ã€ã®ã€ã³ã¹ã¿ã³ã¹ããããŸãã
ãŸãšã
ããŒã«ã䜿çšããæèŠã¯2ã€ãããŸãã ç§ã¯èªåãç¬åµçãªããã°ã©ããŒã§ãããšã¯èããŠããªãããããã®ããŒã«ã¯ããå€ãã®ãšã©ãŒãæããã«ãããšæ³å®ããŸããã å®éãä¿®æ£ãã䟡å€ã®ããããããã1ã€ãããŸããã èªåã®ããšãã²ã©ãèããããããŒã«ããŸã å®å šã«ç£šãããŠããŸããã
ãã®ããŒã«ã¯ã 6å ïŒ 2.11ïŒ ïŒã®ç¡æã¢ã©ãŒããš278å ïŒ 97.89ïŒ ïŒã®ææã¢ã©ãŒããçºè¡ããŸããïŒ3çªç®ã®ã«ããŽãªãŒãªãïŒã ã»ãšãã©ç¡æã§ã¯ãªãã®ã§ãè©ŠããŠããããããŸããã V112 ïŒããžãã¯ãã³ããŒïŒã«é¢é£ããèŠåã¯1ã€ã®èª€æ€ç¥ãäžããŸãããå€ãã®èŠåããããŸã-ç¹ã«æ¯æããè¡ãããŠããã®ã§ããã§ãã¯ã«ããããããŸãã
ãã®ããŒã«ãè³Œå ¥ããŸããïŒ æ®å¿µãªããããããŸããã å€æ°ã®èª€æ€ç¥ã®ãããã»ããã¢ãããšåæã«å€ãã®æéãè²»ãããŸããã 500件è¿ãã®èŠåã«å¯Ÿãã1ã€ã®èª€æ€ç¥ã¯ãããŸãã«ãæ®é ·ã§ãã é©ãã¹ãããšã«ãæçšãªèŠåã¯3ã€ã®ã«ããŽãªã«åé¡ãããŸããïŒæãéèŠã§ã¯ãªãããšãç解ããããïŒã èªåçæããããã¡ã€ã«ã§250åã®ã¢ã©ãŒããèŠã€ãããŸããã ãã®ãããªãã¡ã€ã«ãåŠçããé€å€ããäºåèšå®ïŒããšãã°ãQt mocãã¡ã€ã«ïŒãèŠããã§ãã äœããããèŠåV401ã«æºè¶³ããŸããïŒãµã€ãºãå°ããããããšãã§ããŸãïŒã ããã¯ç§ãè²·ããã®ã§ãïŒ ãã¹ãŠã®èŠåãè³Œå ¥ããŠããµã€ãºãçž®å°ããã¢ããªã±ãŒã·ã§ã³ã®é床ãäžããããšãã§ããŸãã
ããããšã