æè¿ãPascalABC.NETãããžã§ã¯ãã³ãŒãã«åºã¥ããŠãPVS-StudioãšSonarQubeã®CïŒã¢ãã©ã€ã¶ãŒãæ¯èŒããŸããã ãã®ç 究ã¯éåžžã«èå³æ·±ãããšãããã£ãããããã®æ¹åã§äœæ¥ãç¶ããããšã«ããŸããã ä»åã¯ãCïŒã¢ãã©ã€ã¶ãŒPVS-StudioãšVisual Studioã«çµã¿èŸŒãŸããéçã¢ãã©ã€ã¶ãŒãæ¯èŒããŠããŸãã ç§ã®æèŠã§ã¯ãããã¯éåžžã«äŸ¡å€ã®ããçžæã§ãã Visual Studioã¹ã€ãŒãã®ã¢ãã©ã€ã¶ãŒã¯äž»ã«ãšã©ãŒãæ€çŽ¢ããããã§ã¯ãªããã³ãŒãã®å質ãåäžãããããã«èšèšãããŠãããšããäºå®ã«ãããããããããã¯å®éã®ãšã©ãŒãèŠã€ããããã«äœ¿çšã§ããªãããšãæå³ããŸããããããã¯å°é£ã§ãã ä»åã®èª¿æ»ã®éçšã§ãã¢ãã©ã€ã¶ãŒã®ã©ã®æ©èœãæããã«ãªãããèŠãŠã¿ãŸãããã ã©ããïŒ
ã¯ããã«
ãŸããããã€ãã®ãã€ã³ããæ確ã«ããããã®å°ããªFAQã»ã¯ã·ã§ã³ã
QïŒCruiseControl.NETã䜿çšããçç±ã¯äœã§ããïŒ ããã¯ã©ã®ãããªãããžã§ã¯ãã§ããïŒ
AïŒ CruiseControl.NETã¯ã.NET Frameworkã䜿çšããŠå®è£ ãããèªåé£ç¶çµ±åãµãŒããŒã§ãã CruiseControl.NETãœãŒã¹ã³ãŒãã¯GitHubã§å ¥æã§ããŸã ã ãã®ãããžã§ã¯ãã¯éçºãããŠãããããã°ãããµããŒããããŠããŸããããæè¿ã§ã¯äžå®ã®äººæ°ããããŸããã ããã«ãããã¢ãã©ã€ã¶ãŒãæ¯èŒããç®çã§ã®äœ¿çšã劚ããããããšã¯ãããŸããããéã«ãå®å®æ§ã®èŠçŽ ãç 究ã«å°å ¥ãããŸãã PVS-Studioã®ææ°ããŒãžã§ã³ãŸãã¯Visual Studioã«çµã¿èŸŒãŸããã¢ãã©ã€ã¶ãŒã䜿çšããŠã誰ãã³ãŒããæ¹åããŠããªãããšã確èªã§ããŸãã è¿œå ã®ãã©ã¹ã¯ãCruiseControl.NETã®å°ããªãµã€ãºã§ãããããžã§ã¯ãã«ã¯çŽ256äžè¡ã®ã³ãŒããå«ãŸããŸãã
QïŒVisual Studio 2017ã䜿çšããŸãããïŒ ææ°ããŒãžã§ã³ã®åæããŒã«ã®æ©èœã«ã€ããŠç¥ããããšæããŸãã
AïŒVisual Studio 2017ã³ãã¥ããã£ã䜿çšããŠãäž¡æ¹ã®ããŒã«ãåæããŸããã
QïŒã¢ãã©ã€ã¶ãŒã®èšå®ã¯ã©ãã§ããïŒ ããããããã¹ãŠããç¹å¥ã«æ§æãããŠãããã®ã§ãPVS-Studioã®æ¹ãåªããŠãããšå€æããã®ã§ããããïŒ
AïŒããã©ã«ãèšå®ã¯äž¡æ¹ã®ã¢ãã©ã€ã¶ãŒã§äœ¿çšãããŸããã å®éšã®çŽåºŠãé«ããããã«ãWindows 10ãæèŒãããã¯ãªãŒã³ããªãã·ã³ã§ã€ã³ã¹ããŒã«ãšç 究ãå®æœããŸããã
QïŒããã§ããã ãããã確ãã«ãçµæãå°ããªã°ããããèšç®ãæ£ãããªãã£ãã®ã§ããããïŒ ããšãã°ãPVS-Studioã®å ŽåãäœèŠåã®ä¿¡é Œæ§ã¬ãã«ãèæ ®ãããé«ãšäžã®ã¿ãååŸããå ŽåããããŸãã ãããããšãPVS-Studioã«ã¯Visual Studioã«çµã¿èŸŒãŸããã¢ãã©ã€ã¶ãŒãããå©ç¹ããããŸããåŸè ã¯åæ§ã®æ§æãæããªãããã§ãã
AïŒçµæãåæãããšãã絶察ã«ãã¹ãŠã®èŠåã¬ãã«ãèæ ®ãããå©çšå¯èœãªãã¹ãŠã®çš®é¡ã®èšºæãå«ãŸããŸããã
QïŒåæçšã®ãã¡ã€ã«ã®éžæã¯ã©ãã§ããïŒ åäœãã¹ããªã©ãäŸå€ã«äœãè¿œå ããŸãããïŒ
AïŒäž¡æ¹ã®ã¢ãã©ã€ã¶ãŒã«ã€ããŠãäŸå€ãªããœãªã¥ãŒã·ã§ã³å šäœããã§ãã¯ãããŸããã åæã«ãCruiseControl.NETã«ã¯ãUnitTestsããšãããããžã§ã¯ããå«ãŸããŠããŸãã ãã®ãããžã§ã¯ãã§ã¯éåžžã«å€ãã®èŠåãçºè¡ãããŸããããå®éã®ãšã©ãŒãæ€çŽ¢ããéã«ã¯ãã¹ãŠã®èŠåãèæ ®ãããŸããã§ããããèŠåã®çºè¡æ°ã®å šäœçãªã€ã³ãžã±ãŒã¿ã«è¡šç€ºãããŸãã
QïŒæ¬åœã®ééãã§ããïŒ ãã®çšèªã¯äœã§ããïŒ
AïŒç§ãã¡ã®ç解ã§ã¯ããããã¯å®è¡ã«äžå¯æ¬ ãªãšã©ãŒã§ãããé«ã確çã§äŸå€ã®ã¹ããŒãããã°ã©ã ã®äžæ£ãªåäœãããã³äžæ£ãªçµæã®çºè¡ã«ã€ãªãããŸãã ããã§ä¿®æ£ããå¿ èŠããããšã©ãŒã ãããã¯èšèšãæ¹åããããã®æšå¥šäºé ã§ã¯ãªããæçµçµæã«åœ±é¿ãäžããªãã³ãŒãã®è€è£œãªã©ã®å°ããªæ¬ é¥ã§ã¯ãããŸããã CruiseControl.NETã³ãŒãã®å®éã®ãšã©ãŒã®äŸïŒ
public override string Generate(IIntegrationResult integrationResult) { .... IntegrationSummary lastIntegration = integrationResult.LastIntegration; // <= if (integrationResult == null || ....) // <= { .... } .... }
å€ãã®ã¢ãã©ã€ã¶ãŒã¯ãæåã«nullããã§ãã¯ããã«integrationResultå€æ°ã䜿çšãããããšãã³ãŒãã¹ããããã«èŠåããŸã ã ããã¯æ£ããã§ãããéåžžã¯å€æ°ã®èª€æ€ç¥ã«ã€ãªãããŸããããã®äžã§å®éã®ãšã©ãŒãèŠã€ããããšã¯éåžžã«å°é£ã§ãã ç§ãã¡ã®ã¢ãããŒãã¯ãå®éã®ãšã©ãŒãæ€åºããå¯èœæ§ãé«ããè¿œå ã®åæãè¡ãããšã§ãã äžèšã®ã¹ããããã§ã¯ãå€æ°ã䜿çšããåŸã nullããã§ãã¯ãããŸã ã ã€ãŸã ãã®å Žåã®ããã°ã©ãã¯ãã¡ãœããã«æž¡ããåŸãå€æ°ã®å€ãnullã«ãªãå¯èœæ§ããããšæ³å®ãããã§ãã¯ãè¡ããŸãã ããã¯ãŸãã«ééããšèããããç¶æ³ã§ãã ã¡ãœããã«nullã® integrationResultãã§ãã¯ãå«ãŸããŠããªãå Žåãç§ãã¡ã®æèŠã§ã¯ãããã¯èª€æ€ç¥ã«ãªããŸãã
public override string Generate(IIntegrationResult integrationResult) { .... IntegrationSummary lastIntegration = integrationResult.LastIntegration; .... }
PVS-Studioã¢ãã©ã€ã¶ãŒã¯ãã®ã³ãŒããã©ã°ã¡ã³ãã®èŠåãçæããŸããããå€ãã®ã¢ãã©ã€ã¶ãŒã¯ãããè¡ããŸãã ãããŠããã®çµæããã®ãããªã¡ãã»ãŒãžã¯ç¡èŠãããããããã°ã©ããŒã«ãã£ãŠç¡å¹ã«ãããŸãã å€ãã®èŠåã¯è¯ãããšãæå³ããŸããã
QïŒæ¬åœã«ãã¹ãŠãæ£ããè¡ã£ããšããŸãããã ãããããªãç§ã¯ããããã¹ãŠä¿¡ä»°ã«ãšããªããã°ãªããªãã®ã§ããïŒ ã©ãããã°ç 究ãç¹°ãè¿ãããšãã§ããŸããïŒ
AïŒãã以äžç°¡åãªããšã¯ãããŸããã Visual Studioã«çµã¿èŸŒãŸããŠããã¢ãã©ã€ã¶ãŒã¯ç¡æã§ãã Visual Studio 2017 Communityã®ç¡æããŒãžã§ã³ãã€ã³ã¹ããŒã«ããã ãã§ãã PVS-Studioã䜿çšããŠCruiseControl.NETãåæããã«ã¯ã ããŠã³ããŒãããŠãã¢ã¢ãŒãã§äœ¿çšããã ãã§ãã ã¯ããå¶éã«ããå®å šãªåæãè¡ãããšã¯ã§ããŸããããç§ãã¡ã«æžã蟌ãããšãã§ããäžæçãªã©ã€ã»ã³ã¹ããŒãéä¿¡ããŸãã
ç 究ãšçµæ
ããžã¥ã¢ã«ã¹ã¿ãžãª
Visual Studioã®çµã¿èŸŒã¿ã¢ãã©ã€ã¶ãŒã䜿çšããŠãããžã§ã¯ãã³ãŒãããã§ãã¯ããã®ã«æ°åããããããŸããã§ããã ãã®çŽåŸã®çµæã¯æ¬¡ã®ãšããã§ãïŒãã£ã«ã¿ãŒã¯å«ãŸããŸããïŒã
ã¢ãã©ã€ã¶ãŒã¯10773ã®èŠåãçºè¡ããŸããã ã¯ããããã§ãšã©ãŒãæ¢ãã®ã¯ããã»ã©ç°¡åã§ã¯ãããŸããã æåã«ããã£ã«ã¿ãŒã䜿çšããŠããã®ãªã¹ããããUnitTestsããããžã§ã¯ãããèŠåãé€å€ããŸãã
ããã èŠåã®ã»ãŒååã¯ãã¹ãã®ããã«åä¿¡ãããŸããããããã¯é©ãããšã§ã¯ãããŸããã ããããæ®ãã®5,000ãè¶ ããã¡ãã»ãŒãžã§ãååã§ã¯ãããŸããã ãããã®èŠåã¯ã次ã®ã°ã«ãŒãã«å±ããŸãã
Microsoft.Design: CA10XX (: 40, : 1637) Microsoft.Globalization: CA13XX (: 7, : 1406) Microsoft.Interoperability: CA14XX (: 2, : 10) Microsoft.Maintainability: CA15XX (: 3, : 74) Microsoft.Mobility: CA16XX (: 1, : 1) Microsoft.Naming: CA17XX (: 17, : 1071) Microsoft.Performance: CA18XX (: 15, : 489) Microsoft.Portability: CA19XX (: 1, : 4) Microsoft.Reliability: CA20XX (: 4, : 158) Microsoft.Globalization, Microsoft.Security: CA21XX (: 5, : 48) Microsoft.Usage: CA22XX (: 18, : 440)
å€æ°ã®ã³ã³ãã€ã©èŠåãçºè¡ãããŠããŸãã ã©ããããåãåã£ãã¢ãã©ã€ã¶ãŒèšºæã®ããããã®èª¬æã調æ»ããå¿ èŠãªå Žåã«ã®ã¿èŠåã®èª¿æ»ãå®æœãã以å€ã«éžæè¢ã¯ãããŸããã
ããã«ãã®äœæ¥ãè¡ã£ããšèšããŸãããã¢ãã©ã€ã¶ãŒã«ãã£ãŠçºè¡ããã5,000ãè¶ ããèŠåãããšã©ãŒãèŠã€ããã®ã«åœ¹ç«ã€ãã®ã¯ã»ãšãã©èŠã€ãããŸããã§ããã ååãšããŠããã¹ãŠã¯èšèšãšã³ãŒãã®æé©åãæ¹åããããã®æšå¥šäºé ã«åºã¥ããŠããŸãã å€æ°ã®èšºæã«ãŒã«ã®ããã説æãå«ãå®å šãªãªã¹ãã¯æäŸããŸããã å¿ èŠã«å¿ããŠãVisual Studioã«çµã¿èŸŒãŸããã¢ãã©ã€ã¶ãŒã䜿çšããŠCruiseControl.NETãããžã§ã¯ããåå¥ã«ãã§ãã¯ããããšã«ããããã®ãªã¹ãã培åºçã«èª¿ã¹ãããšãã§ããŸãã 蚺æã®è©³çŽ°ãªèª¬æã¯ã MSDNã§å ¥æã§ããŸãã
èŠåã®å€§éšåã調æ»ããŸãããããã¹ãŠã§ã¯ãããŸããã æåŸãŸã§ãã¡ãã»ãŒãžã®å€ãã®ã°ã«ãŒãã衚瀺ããŠãæå³ããããŸããã§ããããããã¯ãã¹ãŠåãã¿ã€ãã§ãããæããã«ãšã©ãŒã«é¢ãããã®ã§ã¯ãªãã£ãããã§ãã æ ¹æ ããªãããã«ãåã°ã«ãŒãã«1ã€ã®äŸãæããŸãã
Microsoft.Design
CA1002ãCruiseServerClient.ForceBuildïŒstringãList <NameValuePair>ïŒãã®ãList <NameValuePair>ããå€æŽããŠãCollection <T>ãReadOnlyCollection <T>ããŸãã¯KeyedCollection <KãV> CruiseServerClient.csã䜿çšããŸã118
public override void ForceBuild(...., List<NameValuePair> parameters) { .... }
ã¡ãœããã®parameters ãã©ã¡ãŒã¿ãŒã«ã¯ã Listã§ã¯ãªãããŠãããŒãµã«ã³ã¬ã¯ã·ã§ã³ïŒ Collectionãªã© ïŒã䜿çšããããšããå§ãããŸãã
Microsoft.Globalization
CA1300ãAddProjects.RetrieveListOfProjectsïŒBuildServerïŒããå€æŽããŠãMessageBoxOptionsãæå®ããMessageBox.ShowãªãŒããŒããŒããåŒã³åºããRightToLeftãRightToLeftã«èšå®ãããŠããå Žåã¯ãMessageBoxOptions.RightAlignããã³MessageBoxOptions.RtlReadingãèšå®ããŸãã CCTrayLib AddProjects.cs 86
private void RetrieveListOfProjects(....) { .... MessageBox.Show(this, "Unable to connect to server " + server.DisplayName + ": " + ex.Message, "Error"); .... }
æšå¥šäºé ã¯ã MessageBoxOptionsåŒæ°ãåãMessageBox.ShowïŒïŒã¡ãœãããªãŒããŒããŒãã䜿çšããããšã§ãã ããã¯ãå³ããå·Šãžã®èªã¿åãé åºã䜿çšããå€èšèªã€ã³ã¿ãŒãã§ã€ã¹ãšèšèªãããé©åã«ãµããŒãããããã«å¿ èŠã§ãã
Microsoftãçžäºéçšæ§
CA1401 P / Invoke 'NativeMethods.SetForegroundWindowïŒIntPtrïŒ'ã®ã¢ã¯ã»ã·ããªãã£ãå€æŽããŠãã¢ã»ã³ããªã®å€éšããèŠããªããªãããã«ããŸãã CCTrayLib NativeMethods.cs 12
[DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetForegroundWindow(IntPtr handle);
DllImportAttributeå±æ§ãæã€ã¡ãœããã®ãããªãã¯ã¢ã¯ã»ã¹ã¬ãã«ãæå®ããªãããšããå§ãããŸãã
Microsoft.Maintainability
CA1500ãerrorMessagesãã¯ããResponse.ConcatenateErrorsïŒïŒãã§å®£èšãããå€æ°ã§ãåã®ã€ã³ã¹ã¿ã³ã¹ãã£ãŒã«ããšåãååãæã£ãŠããŸãã ãããã®ã¢ã€ãã ã®ããããã®ååãå€æŽããŸãã Remote Response.cs 152
private List<ErrorMessage> errorMessages; .... public virtual string ConcatenateErrors() { List<string> errorMessages = new List<string>(); .... }
ããŒã«ã«å€æ°ã®ååãã¯ã©ã¹ãã£ãŒã«ããšåãã§ãããšããèŠåã
Microsoft.Mobility
CA1601ã¡ãœããFileChangedWatcher.FileChangedWatcherïŒparams string []ïŒã® 'Timer.TimerïŒdoubleïŒ'ã®åŒã³åºããå€æŽããŠãã¿ã€ããŒééã1ç§ä»¥äžã®å€ã«èšå®ããŸãã ã³ã¢FileChangedWatcher.cs 33
public FileChangedWatcher(....) { .... timer = new Timer(500); .... }
ã¿ã€ããŒã1ç§æªæºã«èšå®ãããŠãããšããèŠåã
Microsoft.Naming
CA1702ã¡ã³ããŒãAlienbrain.CreateGetProcessïŒstringïŒãã§ã¯ããã©ã¡ãŒã¿ãŒåãfilenameãã®åå¥ã®çšèªãfilenameããè€åèªãfileNameããšããŠè¡šçŸããå¿ èŠããããŸãã ã³ã¢Alienbrain.cs 378
public ProcessInfo CreateGetProcess(string filename) { .... }
ãã£ã¡ã«ã±ãŒã¹ã䜿çšããŠè€åå€æ°åãæå®ããããšã«é¢ããèŠåã
Microsoft.Performance
CA1800å€æ°ãactionãã¯ãã¡ãœãããAdministerPlugin.NamedActions.getïŒïŒãã§ãAdministerActionããè€æ°åå ¥åããããã«ãã£ã¹ããããŸãã åé·ãªisintåœä»€ãæé€ããããã«ããasãæŒç®åãŸãã¯çŽæ¥ãã£ã¹ãã®çµæããã£ãã·ã¥ããŸãã WebDashboard AdministerPlugin.cs 79
public INamedAction[] NamedActions { get { .... if (action is AdministerAction) { (action as AdministerAction).Password = password; } .... } .... }
è€æ°ã®ç¹°ãè¿ããã£ã¹ããæé©åããå¿ èŠæ§ã«é¢ããèŠåã
Microsoft.Portability
CA1901ã³ãŒãã§å®£èšãããŠããããã«ãP / Invoke 'Audio.PlaySoundïŒbyte []ãshortãlongïŒ'ã®ãã©ã¡ãŒã¿ãŒ 'fdwSound'ã¯ã32ããããã©ãããã©ãŒã ã§ã¯8ãã€ãå¹ ã«ãªããŸãã ãã®APIã®å®éã®ãã€ãã£ã宣èšã¯ã32ããããã©ãããã©ãŒã ã§ã¯4ãã€ãå¹ ã§ãªããã°ãªããªãããšã瀺ããŠãããããããã¯æ£ãããããŸããã ãé·ããã®ä»£ããã«ã©ã®ããŒã¿åã䜿çšãã¹ãããå€æããã«ã¯ãMSDN Platform SDKããã¥ã¡ã³ããåç §ããŠãã ããã CCTrayLib Audio.cs 135
[DllImport ("winmm.dll")] private static extern int PlaySound (byte[] pszSound, Int16 hMod, long fdwSound);
ã€ã³ããŒããããã¡ãœããã¯ã fdwSoundãã©ã¡ãŒã¿ãŒã«éããŒã¿ãã«åã䜿çšããããšãèŠåããŸãã IntPtrãŸãã¯UIntPtrã䜿çšããå¿ èŠããããŸãã
Microsoft.Reliability
CA2000ã¡ãœãããAbout.famfamfamLink_LinkClickedïŒãªããžã§ã¯ããLinkLabelLinkClickedEventArgsïŒãã§ããªããžã§ã¯ããurlLinkãã®System.IDisposable.Disposeãããªããžã§ã¯ããžã®ãã¹ãŠã®åç §ãã¹ã³ãŒãå€ã«ãªãåã«åŒã³åºããŸãã CCTrayLib About.cs 71
private void famfamfamLink_LinkClicked(....) { Process urlLink = new Process(); urlLink.StartInfo = new ProcessStartInfo(....); urlLink.Start(); }
ã¹ã³ãŒãå€ã«ãªãåã«urlLink IDisposableãªããžã§ã¯ãã解æŸããå¿ èŠæ§ã«é¢ããèŠåã ããšãã°ãã䜿çšããŠäœ¿çšã§ããŸãã
Microsoft.GlobalizationãMicrosoft.Security
CA2101ã»ãã¥ãªãã£ãªã¹ã¯ã軜æžããã«ã¯ãDllImport.CharSetãCharSet.Unicodeã«èšå®ãããããã©ã¡ãŒã¿ãŒãUnmanagedType.LPWStrãšããŠæ瀺çã«ããŒã·ã£ãªã³ã°ããããšã«ããããã©ã¡ãŒã¿ãŒ 'lpszDomain'ãUnicodeãšããŠããŒã·ã£ãªã³ã°ããŸãã ãã®æååãANSIãŸãã¯ã·ã¹ãã äŸåãšããŠããŒã·ã£ãªã³ã°ããå¿ èŠãããå ŽåãMarshalAsãæ瀺çã«æå®ããBestFitMapping = false;ãèšå®ããŸãã ã»ãã¥ãªãã£ã匷åããã«ã¯ãThrowOnUnmappableChar = trueãèšå®ããŸãã ã³ã¢Impersonation.cs 100
[DllImport("advapi32.dll", SetLastError = true)] private static extern bool LogonUser( string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
ããšãã°ã次ã®ããã«å±æ§ãæå®ããããšã«ãããæåååŒæ°ã®ããŒã·ã£ãªã³ã°ã¿ã€ããæå®ãããŠããªãããšãèŠåããŸãã
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
Microsoft.Usage
CA2201 'CruiseServerClientFactory.GenerateClientïŒstringãClientStartUpSettingsïŒ'ã¯ãã¿ã€ã 'ApplicationException'ã®äŸå€ãäœæããŸããããã¯ãååã«å ·äœçã§ã¯ãªãããŠãŒã¶ãŒã³ãŒãã«ãã£ãŠæ±ºããŠçºçãããªãäŸå€ã¿ã€ãã§ãã ãã®äŸå€ã€ã³ã¹ã¿ã³ã¹ãã¹ããŒãããå¯èœæ§ãããå Žåã¯ãå¥ã®äŸå€ã¿ã€ãã䜿çšããŠãã ããã ãªã¢ãŒãCruiseServerClientFactory.cs 97
public CruiseServerClientBase GenerateClient(....) { .... throw new ApplicationException("Unknown transport protocol"); .... }
äŸå€ã¹ããŒèŠåã¯äžè¬çãããŸãã ãã®å Žåãã©ã³ã¿ã€ã ã§äºçŽãããŠããªããããå ·äœçãªã¿ã€ãã®äŸå€ãã¹ããŒããããšããå§ãããŸãã
ãŸãšã
å®äºããäœæ¥ã®çµæãå®éã®ãšã©ãŒãæ€çŽ¢ããã®ãçã«ããªã£ãŠãããšããçµè«ã«éããŸããããã®å Žåã¯ãMicrosoft.Designã°ã«ãŒãã®ã³ãŒãCA1062ã®ã¡ãã»ãŒãžã®ã¿ãæ€çŽ¢ããŸãã ãããã¯ãã¡ãœãããã©ã¡ãŒã¿ãŒãåç §åã§ããã䜿çšåã«nullãã§ãã¯ãå®è¡ãããªãå Žåã®ç¶æ³ã«é¢ããèŠåã§ãã ãã®ãããªã¡ãã»ãŒãžã«ãã£ã«ã¿ãŒãé©çšãããšã次ã®çµæãåŸãããŸãã
733ã¯ãŸã ãããããããŸãã ããããããªããèŠãããã«ãããã¯ãã§ã«äœãã§ãã ãŸããèŠã€ãã£ãã³ãŒããã©ã°ã¡ã³ãã調ã¹ããšãå®éã«ã¯æœåšçã«å®å šã§ã¯ãããŸããã ããšãã°ãItemStatus.csãã¡ã€ã«ã§ã¯ïŒ
public void AddChild(ItemStatus child) { child.parent = this; childItems.Add(child); }
ItemStatusã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãžã®åã®åç §ã¯ã䜿çšåã«ãã¹ããããŸããã ã¯ããããã¯å±éºã§ãã ããããæ®å¿µãªãããããã¯ééããšã¯èšããŸããã ãããããåŒã³åºãã³ãŒãã«ãã§ãã¯ãå«ããããšãã§ããŸãããããã¯æ£ãããããŸããã ããã«ãã¡ãœããã¯publicãšããŠå®£èšãããŸãã ãã¡ãããã³ãŒãã®äœæè ã¯å¯Ÿçãè¬ããäœããã®æ¹æ³ã§ããããã¹ãŠã®èŠåã«å¯Ÿå¿ããå¿ èŠããããŸãããèŠåã733ããããšãæãåºãããŠãã ãããã»ãšãã©ã®å Žåãããã°ã©ããŒã¯äœãããŸããã ããã¯ãå€ããå°ãªããçããããã®ãã¹ãŠã«å€§éã®ã¡ãã»ãŒãžãçºè¡ããå±éºæ§ã§ãã ãã®ãããéçºè ã«æ³šæãæã䟡å€ã®ããå®éã®ãšã©ãŒã®äŸã以åã«ç€ºããŸããã ãã®ãããªåäœã¯ãã»ãšãã©ã®å ŽååœãšèŠãªãããšãã§ããŸãã ãããŠãæ¬åœã«ããã§ãã
ããå€ãã®æéãè²»ãããŠãçºè¡ããã733åã®èŠå-5ã匷調衚瀺ããŸãããããã¯ãšã©ãŒãšè§£éã§ããŸãã ãããã®1ã€ïŒBuildGraph.csãã¡ã€ã«ïŒã®äŸã次ã«ç€ºããŸãã
public override bool Equals(object obj) { if (obj.GetType() != this.GetType() ) return false; .... }
objå€æ°ã¯ã䜿çšåã«nullããã§ãã¯ãããŸããã ããã¯ãªãŒããŒããŒããããEqualsã¡ãœããã§ããããããšã©ãŒãåŠçããŠããŸãã Equalsã¡ãœããã¯ãnullåç §ãæ£ããåŠçããå¿ èŠããããŸãã ããããCruiseControl.NETãããžã§ã¯ãã§ã¯ããã®ãããªç¶æ³ã¯çºçããŸããããã¡ãœããã³ãŒãã¯äŸç¶ãšããŠãšã©ãŒã§ãããä¿®æ£ããå¿ èŠããããŸãã
现å¿ã®æ³šæãæã£ãèªè ã¯ãã¡ãœããã®ãã¹ãŠã®äœ¿çšãæ éã«èª¿ã¹ãããšãªããããçš®ã®ééããèŠéããŠããå¯èœæ§ãããããšã«å察ãããããããŸããã ããããã ãããå®éã«ã¯ã誰ãåèŠåã泚ææ·±ã調ã¹ãªãããã誀æ€ç¥ã®å²åã¯éåžžã«é«ããªããŸãã
Visual Studioã«çµã¿èŸŒãŸããã¢ãã©ã€ã¶ãŒã䜿çšããŠCruiseControl.NETã³ãŒãã§å®éã®ãšã©ãŒãèŠã€ããããšãã§ããã«ãããããããããã»ã¹èªäœã¯çŽ8æéïŒ1å¶æ¥æ¥ïŒãããã泚æãšéäžåãå¿ èŠã§ããã ããããããããžã§ã¯ãã®äœæè ãéçåæãå®æçã«äœ¿çšããå Žåãå šäœåã¯ãããã©è²ã«ãªããŸãã
PVS-Studio
ç§ã®ãã·ã³ã§PVS-Studioã䜿çšããŠãããžã§ã¯ãã³ãŒãããã§ãã¯ããã«ã¯ãã¡ããã©1åããããŸããã ãã®çŽåŸãçµæã¯æ¬¡ã®ããã«ãªããŸãïŒãã£ã«ã¿ãŒã¯å«ãŸããŸããïŒã
ã¢ãã©ã€ã¶ãŒã¯198åã®èŠåãçæããŸããã ãããŠããã®ãã¡45件ã¯UnitTestsãããžã§ã¯ãã§åä¿¡ãããããã«32件ã®èŠåã®åªå 床ã¯äœããªã£ãŠããŸãïŒå®éã®ãšã©ãŒãèŠã€ããã®ã¯å°é£ã§ãïŒã åèš-åæçšã®121ã®ã¡ãã»ãŒãžãç§ã¯30åãè²»ãããŸããã ãã®çµæã19ã®ãšã©ãŒãç¹å®ãããŸããã
ãããã®1ã€ã®äŸã次ã«ç€ºããŸãã
V3003 ãifïŒAïŒ{...} else ifïŒAïŒ{...}ããã¿ãŒã³ã®äœ¿çšãæ€åºãããŸããã è«çãšã©ãŒãååšããå¯èœæ§ããããŸãã è¡ã確èªããŠãã ããïŒ120ã125ãCCTrayLib CCTrayProject.cs 120
public override bool Equals(object obj) { .... if ((buildServer != null) && (objToCompare.buildServer != null)) { // If both instances have a build server then compare the build // server settings isSame = string.Equals(buildServer.Url, objToCompare.buildServer.Url); } else if ((buildServer != null) && (objToCompare.buildServer != null)) { // If neither instance has a build server then they are the same isSame = true; } .... }
äž¡æ¹ã®ifãããã¯ã«åãæ¡ä»¶ãå«ãŸããŠããŸãã ããã°ã©ã ã®ããžãã¯ã«åœ±é¿ãåãŒããäºæããªãçµæã«ã€ãªããé倧ãªãã¹ãçºçããŸããã
PVS-Studioãæ€åºãããšã©ãŒã®äžã«ã¯ãVisual-Studioã«çµã¿èŸŒãŸããã¢ãã©ã€ã¶ãŒãæ€åºãããšã©ãŒããéžæãããã®ããããŸãã
ããã«ãã以äžè¿œå ãããã®ã¯ãªããšæããŸãã PVS-Studioã¯ãå®éã®ãšã©ãŒãèŠã€ãããšããä»äºãè¿ éãã€å¹ççã«è¡ããŸããã ãããããã®ããã«åœŒã¯ååšããŸãïŒ
ãããã«
çµæãè¡šã«ç€ºããŸãã
ãã¡ãããPVS-Studioã®åŽé¢ã«ã¯æãããªå©ç¹ããããŸãã ãã ããVisual Studioã«çµã¿èŸŒãŸããŠããã¢ãã©ã€ã¶ãŒã¯ããŸããèšèšãšã³ãŒãã®æé©åãæ¹åããããšãç®çãšããŠããããšã©ãŒãæ€çŽ¢ããããšãç®çãšããŠããŸããã äžæ¹ãPVS-Studioã¯ãå¯èœãªéãäœãã¬ãã«ã®èª€ã£ãèŠåãçºè¡ããŠãšã©ãŒãæ€çŽ¢ããããã«ãæçããããŸãã ãŸããCruiseControl.NETã®éçºè ã¯ãã¢ãã©ã€ã¶ãŒããŸã£ãã䜿çšããªãã£ãããã§ãã Visual Studioã«çµã¿èŸŒãŸããŠããã¢ãã©ã€ã¶ãŒãå®æçã«äœ¿çšãããšãã³ãŒãã®å質ãã¯ããã«åäžãããšã©ãŒãçºçããå¯èœæ§ãäœããªããšç¢ºä¿¡ããŠããŸãã PVS-Studioã«ã€ããŠèšãã¹ãããšã ãã®ãããªããŒã«ã䜿çšãããšãã1幎ã«1åãã§ã¯ãªããå®æçã«äœ¿çšããŠæ倧éã®å¹æãåŸãããšãã§ããŸãã
â PVS-StudioãããŠã³ããŒãããŠãè©Šããã ãã
PVS-Studioã®åçšã©ã€ã»ã³ã¹ã®ååŸã«ã€ããŠã¯ãã¡ãŒã«ã§ãåãåãããã ããã ãã¢ããŒãžã§ã³ã®å¶éãåé€ããå Žåã¯ãPVS-Studioã®å æ¬çãªç 究ã®äžæçãªã©ã€ã»ã³ã¹ãååŸããããã«ç§ãã¡ã«æžã蟌ãããšãã§ããŸãã
ãµã€ããªã³ã¯
- éçã¢ãã©ã€ã¶ãŒãåœéœæ§ãšæŠãæ¹æ³ãšçç± ã
- SonarQubeïŒSonarCïŒããã³PVS-Studioã®ãã©ã°ã€ã³ã䜿çšããŠPascalABC.NETãããžã§ã¯ãã確èªããŸã ã
ãã®èšäºãè±èªåã®èŽè¡ãšå ±æãããå Žåã¯ã翻蚳ãžã®ãªã³ã¯ã䜿çšããŠãã ããïŒSergey Khrenovã CruiseControl.NETã³ãŒãããŒã¹ã䜿çšããPVS-Studio for CïŒãšçµã¿èŸŒã¿ã®Visual Studioã¢ãã©ã€ã¶ãŒã®æ¯èŒ
èšäºãèªãã§è³ªåããããŸããïŒ
å€ãã®å Žåãèšäºã«ã¯åã質åãå¯ããããŸãã ããã§åçãåéããŸããïŒ PVS-StudioããŒãžã§ã³2015ã«é¢ããèšäºã®èªè
ããã®è³ªåãžã®åç ã ãªã¹ããã芧ãã ããã