PVS-Studioã¢ãã©ã€ã¶ãŒã®å®éšçããããCïŒ-projectsãåæã§ããäžçäžã«è¡šç€ºã§ããŸãã ããã¯ãªãªãŒã¹ã§ã¯ãªããããŒã¿çã§ããããŸããã ããã¯ãçŸåšã®PVS-Studioã®ãã«ãã§ãã ãŠãŒã¶ãŒãŸãã¯æœåšçãªãŠãŒã¶ãŒããCïŒãµããŒãã«é¢ãããã£ãŒãããã¯ãã§ããã ãæ©ãååŸããããšèããŠããŸãã ãã®ãããCïŒãããžã§ã¯ãã§PVS-Studioã®æ°ããããŒãžã§ã³ãè©ŠããŠã¿ãŠãçµæãæ¬ ç¹ãåžæãè¡šæããæ奜家ãåéããŠããŸãã ããããããã¡ãããã®èšäºã§ã¯ã次ã®ãããžã§ã¯ãã§ããSharpDevelopã®æ€èšŒçµæã«ã€ããŠèª¬æããŸãã
PVS-Studio
ããã§éèŠãªè³ªåã®1ã€ã¯ããCïŒçšã®å¥ã®ã³ãŒãåæããŒã«ãäœæããçç±ãã§ãã
移åããå Žæãšçç±ãæ確ã«ç解ããããã«ãæœåšçãªãŠãŒã¶ãŒãšèªåèªèº«ã®äž¡æ¹ã«åçããŠã¿ãŸãããã
C / C ++èšèªçšã®PVS-Studioã¢ãã©ã€ã¶ãŒãäœæããéçºãç¶ç¶ããŠããŸãã ãã®ã¢ãã©ã€ã¶ãŒã¯ãããŸããŸãªã¿ã€ãã®ãšã©ãŒãèå¥ããããã®å€ãã®èå³æ·±ããŠããŒã¯ãªã¢ã€ãã¢ãå®è£ ããŠããŸãã æéãçµã€ã«ã€ããŠãå®è£ ããã蚺æã®å€ããç¹å®ã®ããã°ã©ãã³ã°èšèªã«é¢é£ä»ããããŠããªãããšãæããã«ãªããŸããã 䜿çšããèšèªã¯é¢ä¿ãããŸããã ã¿ã€ããã¹ãäžæ³šæã«ãããšã©ãŒããŸãã¯ã³ããŒããŒã¹ãã®å€±æãåžžã«ãããŸãã
ãããŠãç§ãã¡ã®çµéšãå¥ã®ããã°ã©ãã³ã°èšèªã§ããCïŒã«é©çšããããšããããšã«ããŸããã ãããã©ãã»ã©æåããããæéã¯ããããŸãã ç§ãã¡ã¯ãå€æ°ã®CïŒéçºè ããå©çãåŸãããšãã§ããéåžžã«èå³æ·±ãããŒã«ãåŸã ã«äœæã§ãããšèããŠããŸãã
çŸåšãç§ãã¡ã®ä»äºã¯ãã§ããã ãæ©ãæœåšçãªãŠãŒã¶ãŒãããã£ãŒãããã¯ãåãåãããšã§ãã PVS-Studioã¢ãã©ã€ã¶ãŒã®ãã«ããŒãžã§ã³ã¯ãŸã æºåãã§ããŠããŸããã çŸåšã蚺æã¯ã»ãšãã©ãããŸããïŒå·çæç¹ã§ã¯36åãããŸããïŒã ãã ãããã®ããŒãžã§ã³ãã€ã³ã¹ããŒã«ããŠè©Šãããšã¯ã§ããŸãã ãããŠããããè¡ããã¹ãŠã®äººã«æè¬ããŸãã äžè¬çã«æ£ããæ¹åã«é²ãã§ãããåæè£ çœ®å šäœãåäœããŠããããšã確èªããããšãéèŠã§ãã ãããŠãæ°ãã蚺æãéåžžã«è¿ éã«è¿œå ããŸãã
ãããã£ãŠãèå³ã®ããæ¹ã¯ã次ã®ãªã³ã¯ããPVS-Studioã®å®éšããŒãžã§ã³ã®ææ°ããŒãžã§ã³ãããŠã³ããŒãããããšããå§ãããŸãïŒ http : //files.viva64.com/beta/PVS-Studio_setup.exe
ã泚æ æéãçµã€ã«ã€ããŠãäžèšã®ãªã³ã¯ã¯ç¡å¹ã«ãªããŸãã ãããã£ãŠãå ¬éãã1ãæ以äžçµéããŠãããã®èšäºãèªãå Žåã¯ãçŸåšã®é åžããŒãžã§ã³ãã€ã³ã¹ããŒã«ããããšããå§ãããŸãïŒ http : //www.viva64.com/en/pvs-studio-download/
èªè ãPVS-Studioãè©Šããããšããªãå Žåã¯ãèšäºã PVS-Studio for Visual C ++ ããèªãããšããå§ãããŸãã ã芧ã®ãšãããC ++ã«çŠç¹ãåœãŠãŠããŸãããå®éã«ã¯éãã¯ãããŸããã ã€ã³ã¿ãŒãã§ã€ã¹ã®èŠ³ç¹ããèŠããšãC ++ãããžã§ã¯ããšCïŒãããžã§ã¯ãã®ã©ã¡ãã§äœæ¥ããŠãéãã¯ã»ãšãã©ãããŸããã
ãã£ãŒãããã¯ãšææ¡ãéä¿¡ããã«ã¯ããã£ãŒãããã¯ããŒãžã䜿çšã§ããŸã ã
SharpDevelopãããžã§ã¯ãã®æ€èšŒ
ããã°ã©ããŒã«ãšã£ãŠãéåžžã®åºåã¯æ©èœããŸããã ããããç§ã¯ãããã®çé¢ç®ã§éåžžã«å¿ããã¯ãªãšã€ã¿ãŒã®æ³šç®ãéããæ¹æ³ãç¥ã£ãŠããŸãã ããŸããŸãªãªãŒãã³ãœãŒã¹ãããžã§ã¯ãããã§ãã¯ã ãããã«é¢ããèšäºãæžããŠããŸãã ç§ãã¡ã®ããŒã«ãäœãã§ãããã瀺ãããšã»ã©è¯ãåºåã¯ãããŸããã
è»èŒªãåçºæããçç±ã¯ãªããšæããŸãã ããŠãåãæ¹æ³ã§ãCïŒããã°ã©ããŒãé äºããŸãã ãŸããéããŠããSharpDevelopãããžã§ã¯ãã®ãã§ãã¯ã«é¢ããå¥ã®èšäºããããŸãã
SharpDevelopã¯ãCïŒãVisual Basic .NETãBooãIronPythonãIronRubyãFïŒãC ++ã®ç¡æã®éçºç°å¢ã§ãã äžè¬çã«Visual Studio .NETã®ä»£æ¿ãšããŠäœ¿çšãããŸãã Mono / GTK +-MonoDevelopã«ããã©ãŒã¯ããããŸãã
ãããžã§ã¯ããå®å šã«CïŒã§èšè¿°ãããŠããããšãéèŠã§ãã ãã®ãããPVS-Studioã®å®éšããŒãžã§ã³ã§ç¢ºèªã§ããŸãã ãããžã§ã¯ãã«ã¯ãæ¡åŒµåããcsãã®8522åã®ãã¡ã€ã«ãããããã®åèšãµã€ãºã¯45ã¡ã¬ãã€ãã§ãã
æãçãããã³ãŒãã¹ãããã
ãã©ã°ã¡ã³ãN1
public override string ToString() { return String.Format("Thread Name = {1} Suspended = {2}", ID, Name, Suspended); }
èŠåPVS-StudioïŒV3025ã®åœ¢åŒãæ£ãããããŸããã 'Format'é¢æ°ãåŒã³åºããšãã«ãç°ãªãæ°ã®å®åŒæ°ãäºæãããŸãã äºæ³ïŒ2.çŸåšïŒ3. Thread.cs 235
å€æ°IDã¯ã決ããŠäœ¿çšãããŸããã ããããããã«æ¬åœã®ééãã¯ãªãã§ãããã ãã ãããã®å Žæã¯æããã«ãã§ãã¯ãã䟡å€ããããŸãã ãããããããã§å®å šã«ç°ãªãã©ã€ã³ã圢æããããšãèšç»ãããŠããã§ãããã
ãã©ã°ã¡ã³ãN2
public override string ToString () { return String.Format ("[Line {0}:{1,2}-{3,4}:{5}]", File, Row, Column, EndRow, EndColumn, Offset); }
èŠåPVS-StudioïŒV3025ã®åœ¢åŒãæ£ãããããŸããã 'Format'é¢æ°ãåŒã³åºããšãã«ãç°ãªãæ°ã®å®åŒæ°ãäºæãããŸãã äºæ³ïŒ4.çŸåšïŒ6. MonoSymbolTable.cs 235
ããèå³æ·±ãã±ãŒã¹ã ããã°ã©ããŒããŸãã«æãã§ããããšã¯ãç§ã«ã¯æããã§ã¯ãããŸããã ããããã圌ã¯æ¬¡ã®ãããªã¡ãã»ãŒãžãäœæãããã£ãã§ãããã
[ãã¡ã€ã«file.csïŒ10,20-30,40ïŒ7]
ããããã©ããã圌ã¯ããã€ãã®ãã¬ãŒã¹ãéããŸããã ãããã£ãŠããã2ããšãã4ãããã£ãŒã«ãã®é 眮ãæå®ããEndRowå€æ°ãšEndColumnå€æ°ã®å€ããŸã£ãã衚瀺ããªãããšãããããŸãã
次ã®æžåŒèšå®è¡ãæ£ããããšãææ¡ããããšæããŸãã
String.Format ("[Line {0}:{1},{2}-{3},{4}:{5}]", File, Row, Column, EndRow, EndColumn, Offset);
ãã©ã°ã¡ã³ãN3
static MemberCore GetLaterDefinedMember(MemberSpec a, MemberSpec b) { var mc_a = a.MemberDefinition as MemberCore; var mc_b = b.MemberDefinition as MemberCore; .... if (mc_a.Location.File != mc_a.Location.File) return mc_b; return mc_b.Location.Row > mc_a.Location.Row ? mc_b : mc_a; }
PVS-StudioèŠåïŒV3001ãïŒ=ãæŒç®åã®å·Šå³ã«åããµãåŒãmc_a.Location.FileãããããŸãã membercache.cs 1306
ããã§ã¯ã¿ã€ããã¹ãæ±ã£ãŠããŸãã 次ã®æ¯èŒãæ£ããéžæè¢ã ãšæããŸãïŒ
if (mc_a.Location.File != mc_b.Location.File)
ãã©ã°ã¡ã³ãN4
public WhitespaceNode(string whiteSpaceText, TextLocation startLocation) { this.WhiteSpaceText = WhiteSpaceText; this.startLocation = startLocation; }
PVS-StudioèŠåïŒV3005ãthis.WhiteSpaceTextãå€æ°ã¯ããèªäœã«å²ãåœãŠãããŸãã WhitespaceNode.cs 65
çŸããééãã ããã§ãéçã¢ãã©ã€ã¶ãŒã¯ãã®æ¬è³ªã瀺ããŸããã 圌ã¯æ°é ããããã人ãšéã£ãŠç²ããŸããã ããã§åœŒã¯ã¿ã€ããã¹ã«æ°ã¥ããã 圌女ãèŠããŸããïŒ åæããŠãééããèŠã€ããã®ã¯ç°¡åã§ã¯ãããŸããã
ãããã£ãŠã1æåã®ã¿ã€ããã¹ã ã= whiteSpaceTextããšæžãå¿ èŠããããŸããã ãããŠãã= WhiteSpaceTextããšè¡šç€ºãããŸãã ãã®çµæãã¯ã©ã¹ã®ãWhiteSpaceTextãã®å€ã¯å€æŽãããŸããã
ããã¯äžè¬ã«ãå€æ°ã«ååãä»ããã¹ãã§ãªãããšã®è¯ãäŸã§ãã 1ã€ã®å°æå/倧æåã ãã§ååãåºå¥ããã®ã¯æªãèãã§ãã ãã ããã³ãŒãã£ã³ã°ã¹ã¿ã€ã«ã«é¢ããè°è«ã¯ãã®èšäºã®ç¯å²å€ã§ãã ããã«ãããã¯ç¥èãªè°è«ã®æŠäºãæã€ã
ãã©ã°ã¡ã³ãN5
new public bool Enabled { get { return base.Enabled; } set { if (this.InvokeRequired) { base.Enabled = this.VScrollBar.Enabled = this.hexView.Enabled =this.textView.Enabled = this.side.Enabled = this.header.Enabled = value; } else { base.Enabled = this.VScrollBar.Enabled = this.hexView.Enabled = this.textView.Enabled = this.side.Enabled = this.header.Enabled = value; } } }
PVS-StudioèŠåïŒV3004ãthenãã¹ããŒãã¡ã³ãã¯ãelseãã¹ããŒãã¡ã³ããšåçã§ãã Editor.cs 225
ãthis.InvokeRequiredãã®å€ã«é¢ä¿ãªããåãã¢ã¯ã·ã§ã³ãå®è¡ãããããšã¯éåžžã«çãããã§ãã æååãbase.Enabled = .....ããã³ããŒãããã®ã§ã¯ãªãããšåŒ·ãæããŸãã ãããŠã圌ãã¯ãã®äžã®äœããå€ããã®ãå¿ããŠããŸããã
ãã©ã°ã¡ã³ãN6ãN7ãN8ãN9
public override void Run() { .... ISolutionFolderNode solutionFolderNode = node as ISolutionFolderNode; if (node != null) { ISolutionFolder newSolutionFolder = solutionFolderNode.Folder.CreateFolder(....); solutionFolderNode.Solution.Save(); .... }
PVS-StudioèŠåïŒV3019ãasãããŒã¯ãŒãã䜿çšããåå€æåŸããããã誀ã£ãå€æ°ãnullãšæ¯èŒãããŸãã å€æ°ãnodeãããsolutionFolderNodeãã確èªããŸãã SolutionNodeCommands.cs 127
ãããŒãããã€ã³ã¿ãŒãã§ãŒã¹ãISolutionFolderNodeãããç¶æ¿ãããå Žåã圌ãã¯ããã€ãã®ã¢ã¯ã·ã§ã³ãå®è¡ãããã£ãã ãããã圌ãã¯ééã£ãå€æ°ããã§ãã¯ããŸããã æ£ãããªãã·ã§ã³ïŒ
ISolutionFolderNode solutionFolderNode = node as ISolutionFolderNode; if (solutionFolderNode != null) {
ã¡ãªã¿ã«ãããã¯CïŒããã°ã©ã ã§ããªãäžè¬çãªãšã©ãŒãã¿ãŒã³ã§ãã ããšãã°ãSharpDevelopãããžã§ã¯ãã§ã¯ããã®ãããªãšã©ãŒãããã«3ã€çºçããŸããã
- V3019ãasãããŒã¯ãŒãã䜿çšããåå€æåŸã«ã誀ã£ãå€æ°ãnullãšæ¯èŒãããå¯èœæ§ããããŸãã å€æ°ãgeometryãããgãã確èªããŠãã ããã PathHandlerExtension.cs 578
- V3019ãasãããŒã¯ãŒãã䜿çšããåå€æåŸã«ã誀ã£ãå€æ°ãnullãšæ¯èŒãããå¯èœæ§ããããŸãã å€æ°ãoldTransformãããtgãã確èªããŸãã ModelTools.cs 420
- V3019ãasãããŒã¯ãŒãã䜿çšããåå€æåŸã«ã誀ã£ãå€æ°ãnullãšæ¯èŒãããå¯èœæ§ããããŸãã å€æ°ãnodeãããsolutionFolderNodeãã確èªããŸãã SolutionNodeCommands.cs 104
ãã©ã°ã¡ã³ãN10
public override void VisitInvocationExpression(....) { .... foundInvocations = (idExpression.Identifier == _varName); foundInvocations = true; .... }
PVS-StudioèŠåïŒV3008ãfoundInvocationsãå€æ°ã«ã¯ãé£ç¶ããŠ2åå€ãå²ãåœãŠãããŸãã ããããããã¯ééãã§ãã è¡ã確èªïŒ211ã209ãRedundantAssignmentIssue.cs 211
éåžžã«çãããåå²ãåœãŠã ããããã2çªç®ã®å²ãåœãŠã¯ãã³ãŒãããããã°ããããã»ã¹ã§èšè¿°ããããã®åŸãããå¿ããŠããŸã£ãã®ã§ãããã
ãšã©ãŒN11
public static Snippet CreateAvalonEditSnippet(....) { .... int pos = 0; foreach (Match m in pattern.Matches(snippetText)) { if (pos < m.Index) { snippet.Elements.Add(....); pos = m.Index; } snippet.Elements.Add(....); pos = m.Index + m.Length; } .... }
PVS-StudioèŠåïŒV3008ãposãå€æ°ã«ã¯é£ç¶ããŠ2åå€ãå²ãåœãŠãããŸãã ããããããã¯ééãã§ãã ãã§ãã¯è¡ïŒ151ã148ãCodeSnippet.cs 151
å¥ã®äžå¯©ãªåå²ãåœãŠã ããã§ã¯ããšã©ãŒãŸãã¯ãpos = m.Index;ããšããå²ãåœãŠã¯äžèŠã§ãã
ãã©ã°ã¡ã³ãN12
.... public string Text { get; set; } .... protected override void OnKeyUp(KeyEventArgs e) { .... editor.Text.Insert(editor.CaretIndex, Environment.NewLine); .... }
PVS-StudioèŠåïŒV3010é¢æ° 'Insert'ã®æ»ãå€ãå©çšããå¿ èŠããããŸãã InPlaceEditor.cs 166
CïŒã®æååã¯äžå€ã§ãã ãããã£ãŠãæååã䜿çšããŠäœããè¡ãå Žåãçµæãã©ããã«ä¿åããå¿ èŠããããŸãã ããããäŸãã°ããã§èµ·ãã£ãããã«ãããã¯å¿ããã¡ã§ãã éçºè ã¯ãInsertïŒïŒã¡ãœãããåŒã³åºãããšã§ãè¡ã«äœããè¿œå ããããšã«ããŸããã ããããããã¯ããã§ã¯ãããŸããã æ£ããã³ãŒãã¯æ¬¡ã®ãšããã§ãã
editor.Text = editor.Text.Insert(editor.CaretIndex, Environment.NewLine);
ãã©ã°ã¡ã³ãN13ãN14
public IEnumerable<PropertyMapping> GetMappingForTable(SSDL.EntityType.EntityType table) { var value = GetSpecificMappingForTable(table); var baseMapping = BaseMapping; if (baseMapping != null) value.Union(baseMapping.GetMappingForTable(table)); return value; }
PVS-StudioèŠåïŒV3010é¢æ°ãUnionãã®æ»ãå€ã䜿çšããå¿ èŠããããŸãã MappingBase.cs 274
äžè¬çã«ãCïŒãããžã§ã¯ãã§ã¯ãããã°ã©ããŒããªããžã§ã¯ãã®å€æŽãäºæããŠãããšããäºå®ã«é¢é£ããããªãã®æ°ã®ãšã©ãŒãçºçãããšããäºæããããŸãããããã¯èµ·ãããŸããã
IEnumerableã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ããã³ã¬ã¯ã·ã§ã³ã«å¯ŸããŠå®çŸ©ããã 'Union'æ¡åŒµã¡ãœããã䜿çšãããšã2ã€ã®ã»ããã®å ±ééšåãååŸã§ããŸãã ãã ããã³ã³ããã®ãå€ãã¯å€æŽãããŸããã æ£ãããªãã·ã§ã³ïŒ
value = value.Union(baseMapping.GetMappingForTable(table));
å¥ã®ãã®ãããªç¶æ³ã¯ããã«ãããŸãïŒV3010é¢æ° 'OrderBy'ã®æ»ãå€ãå©çšããå¿ èŠããããŸãã CodeCoverageMethodElement.cs 124
ãã©ã°ã¡ã³ãN15
PVS-Studioã¢ãã©ã€ã¶ãŒã¯ãããã°ã©ããŒãã¹ã€ããïŒïŒã§äœããè¡ãã®ãå¿ãããããããªãç¶æ³ãç¹å®ããããšããŠããŸãã èŠåãããã©ããã決å®ããããžãã¯ã¯éåžžã«è€éã§ãã 誀æ€åºãåŸãããããšãããã°ãæãããªãšã©ãŒãèŠã€ããããšããããŸãã ãããã®ãã©ã¹ã®1ã€ãæ€èšããŠãã ããã
ãã®ãããã³ãŒãã«ã¯æ¬¡ã®ãããªåæããããŸãã
public enum TargetArchitecture { I386, AMD64, IA64, ARMv7, }
å Žæã§ã¯ããã®ãªã¹ãã®ãã¹ãŠã®ããªã¢ã³ãã䜿çšãããŸãã
TargetArchitecture ReadArchitecture () { var machine = ReadUInt16 (); switch (machine) { case 0x014c: return TargetArchitecture.I386; case 0x8664: return TargetArchitecture.AMD64; case 0x0200: return TargetArchitecture.IA64; case 0x01c4: return TargetArchitecture.ARMv7; } throw new NotSupportedException (); }
ããããçãããå ŽæããããŸãã ããšãã°ãã¢ãã©ã€ã¶ãŒã¯æ¬¡ã®ã³ãŒãã«æ³šæãåããŸããã
ushort GetMachine () { switch (module.Architecture) { case TargetArchitecture.I386: return 0x014c; case TargetArchitecture.AMD64: return 0x8664; case TargetArchitecture.IA64: return 0x0200; } throw new NotSupportedException (); }
PVS-StudioèŠåïŒV3002 switchã¹ããŒãã¡ã³ãã¯ããTargetArchitectureãåæåã®ãã¹ãŠã®å€ãã«ããŒããŠããŸããïŒARMv7ã ImageWriter.cs 209
ã芧ã®ãšãããã¢ãŒããã¯ãã£ãARMv7ã®å Žåã倧æåãšå°æåã¯åºå¥ãããŸããã ãããééããã©ããã¯ããããŸããã ããããããã¯ãŸãã«ééãã§ããããã«æããŸãã ååARMv7ã¯åæã®æåŸã«ãããŸããã€ãŸããæåŸã«è¿œå ãããããšãæå³ããŸãã ãã®çµæãããã°ã©ãã¯GetMachineïŒïŒé¢æ°ã®ä¿®æ£ãå¿ããŠããã®ã¢ãŒããã¯ãã£ãèæ ®ããå¿ èŠããããŸããã
ãã©ã°ã¡ã³ãN15
void DetermineCurrentKind() { ..... else if (Brush is LinearGradientBrush) { linearGradientBrush = Brush as LinearGradientBrush; radialGradientBrush.GradientStops = linearGradientBrush.GradientStops; CurrentKind = BrushEditorKind.Linear; } else if (Brush is RadialGradientBrush) { radialGradientBrush = Brush as RadialGradientBrush; linearGradientBrush.GradientStops = linearGradientBrush.GradientStops; CurrentKind = BrushEditorKind.Radial; } }
PVS-StudioèŠåïŒV3005ãlinearGradientBrush.GradientStopsãå€æ°ã¯ããèªäœã«å²ãåœãŠãããŸãã BrushEditor.cs 120
èªãã¹ãããªãéãã³ãŒãã ãããŠæããã«ãããééããç¯ããçç±ã§ãã ã»ãšãã©ã®å Žåãã³ãŒãã¯Copy-Pasteã¡ãœããã䜿çšããŠèšè¿°ãããŠããã1ç®æã§èª€ã£ãŠå€æŽãããŠããŸãã
ã©ãããã代ããã«ïŒ
linearGradientBrush.GradientStops = linearGradientBrush.GradientStops;
æžãããŠããå¿ èŠããããŸãã
linearGradientBrush.GradientStops = radialGradientBrush.GradientStops;
èã
ã¢ãã©ã€ã¶ãŒãæãå€ãã®ãã©ã°ã¡ã³ãã¯ãã»ãšãã©å®éã®ãšã©ãŒã§ã¯ãããŸããã äžæ¹ããã®ãããªã³ãŒãã§çºè¡ãããã¡ãã»ãŒãžã¯ã誀æ€ç¥ãšãåŒã°ããŸããã éåžžã圌ãã¯èãããããããªã³ãŒãã«ã€ããŠèšããŸãã
äžèšã§ã¯ããšã©ãŒãå«ãã§ãããšæãããå€ãã®ã³ãŒããèŠãŸããã 次ã«ãåãã®äŸãããã€ã瀺ããŸãã ç§ã¯ãã¹ãŠã®ç¶æ³ãèæ ®ããŸããããããã¯é¢çœããªãã§ãã 3ã€ã®äŸã«éå®ããŸãã éçºè ã¯ãSharpDevelopãããžã§ã¯ãããã§ãã¯ã¢ãŠãããããšã§ãæ®ãã®åãã«æ £ããããšãã§ããŸãã
ã¹ããããã³ãŒãã¹ããããN1
protected override bool CanExecuteCommand(ICommand command) { .... } else if (command == DockableContentCommands.ShowAsDocument) { if (State == DockableContentState.Document) { return false; } } .... else if (command == DockableContentCommands.ShowAsDocument) { if (State == DockableContentState.Document) { return false; } } .... }
PVS-StudioèŠåïŒV3003ãifïŒAïŒ{...} else ifïŒAïŒ{...}ããã¿ãŒã³ã®äœ¿çšãæ€åºãããŸããã è«çãšã©ãŒãååšããå¯èœæ§ããããŸãã è¡ã確èªããŠãã ããïŒ773ã798ãDockableContent.cs 773
ã芧ã®ãšãããããã°ã©ã ã«ã¯2ã€ã®åäžã®ãããã¯ãå«ãŸããŠããŸãã äžçªäžã®ãããã¯ãifãã®æ¡ä»¶ã¯æ±ºããŠæºããããŸããã ããããç§ã®æèŠã§ã¯ãããã¯ééãã§ã¯ãããŸããã å¶ç¶ã«ãããã¯ãè€è£œããããã«æããŸãããããã¯äžèŠã§ãã ãã ããããã¯ç¢ºèªããŠä¿®æ£ãã䟡å€ã®ããå Žæã§ãã
ã¹ããããã³ãŒãã¹ããããN2
void PropertyExpandButton_Click(object sender, RoutedEventArgs e) { .... ContentPropertyNode clickedNode = clickedButton.DataContext as ContentPropertyNode; clickedNode = clickedButton.DataContext as ContentPropertyNode; if (clickedNode == null) .... }
PVS-StudioèŠåïŒV3008ãclickedNodeãå€æ°ã«ã¯ãé£ç¶ããŠ2åå€ãå²ãåœãŠãããŸãã ããããããã¯ééãã§ãã è¡ã確èªããŠãã ããïŒ105ã104ãPositionedGraphNodeControl.xaml.cs 105
ã³ãŒãã¯åé·ã§ããã次ã®ããã«ç°¡ç¥åã§ããŸãã
ContentPropertyNode clickedNode = clickedButton.DataContext as ContentPropertyNode; if (clickedNode == null)
ã³ãŒãã¹ããããã¹ããããN3
IEnumerable<ICompletionData> CreateConstructorCompletionData(IType hintType) { .... if (!(hintType.Kind == TypeKind.Interface && hintType.Kind != TypeKind.Array)) { .... }
èŠåPVS-StudioïŒV3023ãã®åŒã®æ€æ»ãæ€èšããŠãã ããã è¡šçŸãéå°ã§ãããã誀æ€ãå«ãŸããŠããŸãã CSharpCompletionEngine.cs 2392
åé·ã³ãŒãã åŒã¯åçŽåã§ããŸãïŒ
if (hintType.Kind != TypeKind.Interface) {
ç¶è¡ã§ããŸãããããã§ååã§ãã ä»ã®ãã¹ãŠã®ãåããã¯ããªãåäžã§ããã§ã«ãªã¹ããããŠãããã®ã«äŒŒãŠããŸãã
ãããã«
ã芧ã®ãšãããCïŒèšèªã ãã§ã¯æããªãšã©ãŒãé²ãããšã¯ã§ããŸããã ãããã£ãŠãç§ã¯ãã®åçãããã«æ確ãªè¯å¿ããã£ãŠæã¡èŸŒãããšãã§ããŸãã
ãŠãã³ãŒã³ã¯é·ãçãç¶ããŸãããŠãã³ãŒã³ã¯ãCïŒããã°ã©ã ã®ãšã©ãŒãèŠã€ããããšãåŠã³ãŸããã
ããããçå£ã«ãããããïŒ
- ããã°ã©ãã³ã°ãããšããç§ãã¡ã¯çãè€éãªã ãã§ãªããåçŽãªééããç¯ããŸãã åèšãããšãåçŽãªãšã©ãŒã®æ€çŽ¢ã«å€ãã®æéãè²»ããããŸãã ãããŠæã ãããã ã
- éçã³ãŒãåæã®ããŒã«ã䜿çšãããšãã³ãŒããèšè¿°ãã段éã§ããå€æ°ã®åçŽãªãšã©ãŒãæ€åºã§ããŸãã ãã®ãããªããŒã«ã䜿çšãããšãå€ãã®æéãç¯çŽã§ããå€ãã®ãšã©ãŒã®æ€çŽ¢ãšãããã°ã«è²»ããããšãã§ããŸãã
- éç解æã§æãéèŠãªããšã¯ãå®æçãªäœ¿çšã§ãã éçåæã®1åéãã®ãã§ãã¯ã«ã¯æå³ããããŸããã ãã®å šäœçãªãã€ã³ãã¯ããšã©ãŒãã³ãŒãã«çŸããçŽåŸã«ãšã©ãŒãèŠã€ããããšã§ãã ãŸããªãã§ãã¯ã¯æéãããããã»ãšãã©åœ¹ã«ç«ã¡ãŸããã çµå±ã®ãšããããã§ã«ãã®ç¬éãŸã§ã«ãã°ããç°¡åã«çºèŠã§ãããããã®ééãã¯ãæ±ãšè¡ã§ä¿®æ£ãããŸããã
ãã®èšäºãè±èªåã®èŽè¡ãšå ±æãããå Žåã¯ã翻蚳ãžã®ãªã³ã¯ã䜿çšããŠãã ããïŒAndrey Karpovã CïŒãµããŒãä»ãã®PVS-Studioã®å®éšç ã
èšäºãèªãã§è³ªåããããŸããïŒ
å€ãã®å Žåãèšäºã«ã¯åã質åãå¯ããããŸãã ããã§åçãéããŸããïŒ PVS-StudioããŒãžã§ã³2015ã«é¢ããèšäºã®èªè
ããã®è³ªåãžã®åç ã ãªã¹ããã芧ãã ããã