Microsoftã®ãããžã§ã¯ãã®ãœãŒã¹ã³ãŒãã®å ¬éã¯ãããããæ€èšŒããæ£åœãªçç±ã§ãã ä»åãäŸå€ã§ã¯ãªããä»æ¥ã¯Infer.NETã³ãŒãã§èŠã€ãã£ãçãããå ŽæãèŠãŠãããŸãã 泚éãä»ããŠãèŠç¹ãç解ããŸãããïŒ
ãããžã§ã¯ããšã¢ãã©ã€ã¶ãŒã«ã€ããŠå°ã
Infer.NETã¯ãMicrosoftã®å°é家ã«ãã£ãŠéçºãããæ©æ¢°åŠç¿ã·ã¹ãã ã§ãã ãããžã§ã¯ãã®ãœãŒã¹ã³ãŒãã¯æè¿GitHubã§å©çšå¯èœã«ãªããŸããããããæ€èšŒã®çç±ã§ããã ãããžã§ã¯ãã®è©³çŽ°ã«ã€ããŠã¯ãããšãã°ãã¡ããã芧ãã ãã ã
ãããžã§ã¯ãã¯ãPVS-StudioããŒãžã§ã³6.26éçã¢ãã©ã€ã¶ãŒã䜿çšããŠãã§ãã¯ãããŸããã PVS-Studioã¯ãWindowsãLinuxãmacOSã®C \ C ++ \ CïŒïŒããã³ãŸããªãJavaïŒã®ã³ãŒãã®ãšã©ãŒãæ¢ããŠããããšãæãåºãããŠãã ããã CïŒã³ãŒãã¯çŸåšWindowsã§ã®ã¿åæãããŠããŸãã ã¢ãã©ã€ã¶ãŒãããŠã³ããŒãããŠããããžã§ã¯ãã§è©Šãããšãã§ããŸãã
ãã§ãã¯èªäœã¯éåžžã«ç°¡åã§ãåé¡ã¯ãããŸããã§ããã 以åã¯ãGitHubãããããžã§ã¯ããã¢ã³ããŒãããå¿ èŠãªããã±ãŒãžïŒäŸåé¢ä¿ïŒã埩å ãããããžã§ã¯ããæ£åžžã«ãã«ããããããšã確èªããŸããã ããã¯ãã¢ãã©ã€ã¶ãŒãå®å šãªåæã«å¿ èŠãªãã¹ãŠã®æ å ±ã«ã¢ã¯ã»ã¹ã§ããããã«ããããã«å¿ èŠã§ãã æ°åã¯ãªãã¯ããã ãã§çµã¿ç«ãŠãåŸãVisual Studioã®PVS-Studioãã©ã°ã€ã³ã䜿çšããŠãœãªã¥ãŒã·ã§ã³ã®åæãéå§ããŸããã
ãšããã§ãããã¯PVS-Studioã䜿çšããŠãã¹ãããMicrosoftã®æåã®ãããžã§ã¯ãã§ã¯ãããŸãããä»ã«ãRoslyn ã MSBuild ã PowerShell ã CoreFXãªã©ããããŸãã ã
ã泚æ ããªããŸãã¯ããªãã®ç¥äººãJavaã³ãŒãã®åæã«èå³ãããå Žåã¯ããJavaçšã®ã¢ãã©ã€ã¶ãŒã欲ããããéžæããããšã§ãµããŒãã«é£çµ¡ã§ããŸãã ã¢ãã©ã€ã¶ãŒã®ãããªãã¯ããŒã¿çã¯ãããŸããããããã«å©çšå¯èœã«ãªãã¯ãã§ãã ç§å¯ã®å®éšå®€ã®ã©ããã§ïŒå£ãéããŠïŒã圌ãã¯ç©æ¥µçã«äœæ¥ããŠããŸãã
ããããååãªæœè±¡çãªè©±-ã³ãŒãã®åé¡ãèŠãŠã¿ãŸãããã
ããã¯ãã°ã§ããããããšãæ©èœã§ããïŒ
èªåã§ãšã©ãŒãèŠã€ããããšããããšããå§ãããŸã-å®å šã«è§£æ±ºå¯èœãªã¿ã¹ã¯ã§ãã æ£çŽãªãšãããã 2017幎ã®C ++ãããžã§ã¯ãã®ããã10ãšã©ãŒ ããšããèšäºã«ãã£ãããšã®ç²Ÿç¥ã«åè«ã¯ãããŸããã ãã®ãããã³ãŒãã¹ããããã®åŸã«æäŸãããã¢ãã©ã€ã¶ãŒã®èŠåãèªãã®ãæ¥ããªãã§ãã ããã
private void MergeParallelTransitions() { .... if ( transition1.DestinationStateIndex == transition2.DestinationStateIndex && transition1.Group == transition2.Group) { if (transition1.IsEpsilon && transition2.IsEpsilon) { .... } else if (!transition1.IsEpsilon && !transition2.IsEpsilon) { .... if (double.IsInfinity(transition1.Weight.Value) && double.IsInfinity(transition1.Weight.Value)) { newElementDistribution.SetToSum( 1.0, transition1.ElementDistribution, 1.0, transition2.ElementDistribution); } else { newElementDistribution.SetToSum( transition1.Weight.Value, transition1.ElementDistribution, transition2.Weight.Value, transition2.ElementDistribution); } .... }
PVS-StudioèŠå ïŒ V3001 ã&&ãæŒç®åã®å·Šå³ã«ã¯ãåäžã®å¯æ¬¡åŒãdouble.IsInfinityïŒtransition1.Weight.ValueïŒãããããŸãã ã©ã³ã¿ã€ã Automaton.Simplification.cs 479
ã³ãŒãã¹ãããããããããããã«ããã®ã¡ãœããã¯å€æ°ã®ãã¢-transition1ãštransition2ã§æ©èœããŠããŸãã åæ§ã®ååã䜿çšããããšã¯æ£åœãªå ŽåããããŸããããã®å Žåãååã®ã©ããã§èª€ã£ãŠãã¹ãããå¯èœæ§ãé«ããªãããšãèŠããŠãã䟡å€ããããŸãã
ããã¯ãç¡éå€§ïŒ double.IsInfinity ïŒã®æ°ããã§ãã¯ãããšãã«èµ·ãã£ãããšã§ãã ãšã©ãŒã®ãããåãå€æ°ã®å€ã2åãã§ãã¯ããŸãã-transition1.Weight.Value ã 2çªç®ã®éšååŒã®ãã§ãã¯ãããå€ã¯ãå€æ°transition2.Weight.Valueã§ããã
å¥ã®åæ§ã®çãããã³ãŒãã
internal MethodBase ToMethodInternal(IMethodReference imr) { .... bf |= BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance; .... }
PVS-StudioèŠå ïŒ V3001 ã|ãã®å·ŠåŽãšå³åŽã«åäžã®å¯æ¬¡åŒãBindingFlags.PublicãããããŸã æŒç®åã ã³ã³ãã€ã©CodeBuilder.cs 194
bfå€æ°ã®å€ã圢æãããšãã BindingFlags.PublicåæèŠçŽ ã2å䜿çšãããŸãã ãã®ã³ãŒãã«ã¯è¿œå ã®ãã©ã°æäœãå«ãŸããŠãããã BindingFlags.Publicã® 2åç®ã®äœ¿çšã®ä»£ããã«ãç°ãªãåæå€ãå¿ èŠã§ãã
ãšããã§ããœãŒã¹ã³ãŒãã§ã¯ããã®ã³ãŒãã¯1è¡ã§èšè¿°ãããŠããŸãã ããŒãã«ã¹ã¿ã€ã«ïŒããã®ãããªïŒã§ãã©ãŒããããããŠããå Žåãåé¡ã®æ€åºã容æã«ãªãããã«æããŸãã
ç¶ããŸãããã ã¡ãœããå šäœãæã¡åž°ãããšã©ãŒïŒãŸãã¯ãšã©ãŒïŒãèªåã§èŠã€ããããšããå§ãããŸãã
private void ForEachPrefix(IExpression expr, Action<IExpression> action) { // This method must be kept consistent with GetTargets. if (expr is IArrayIndexerExpression) ForEachPrefix(((IArrayIndexerExpression)expr).Target, action); else if (expr is IAddressOutExpression) ForEachPrefix(((IAddressOutExpression)expr).Expression, action); else if (expr is IPropertyReferenceExpression) ForEachPrefix(((IPropertyReferenceExpression)expr).Target, action); else if (expr is IFieldReferenceExpression) { IExpression target = ((IFieldReferenceExpression)expr).Target; if (!(target is IThisReferenceExpression)) ForEachPrefix(target, action); } else if (expr is ICastExpression) ForEachPrefix(((ICastExpression)expr).Expression, action); else if (expr is IPropertyIndexerExpression) ForEachPrefix(((IPropertyIndexerExpression)expr).Target, action); else if (expr is IEventReferenceExpression) ForEachPrefix(((IEventReferenceExpression)expr).Target, action); else if (expr is IUnaryExpression) ForEachPrefix(((IUnaryExpression)expr).Expression, action); else if (expr is IAddressReferenceExpression) ForEachPrefix(((IAddressReferenceExpression)expr).Expression, action); else if (expr is IMethodInvokeExpression) ForEachPrefix(((IMethodInvokeExpression)expr).Method, action); else if (expr is IMethodReferenceExpression) ForEachPrefix(((IMethodReferenceExpression)expr).Target, action); else if (expr is IUnaryExpression) ForEachPrefix(((IUnaryExpression)expr).Expression, action); else if (expr is IAddressReferenceExpression) ForEachPrefix(((IAddressReferenceExpression)expr).Expression, action); else if (expr is IDelegateInvokeExpression) ForEachPrefix(((IDelegateInvokeExpression)expr).Target, action); action(expr); }
èŠã€ããïŒ ç¢ºèªäžã§ãïŒ
PVS-Studioã®èŠå ïŒ
- V3003 ãifïŒAïŒ{...} else ifïŒAïŒ{...}ããã¿ãŒã³ã®äœ¿çšãæ€åºãããŸããã è«çãšã©ãŒãååšããå¯èœæ§ããããŸãã è¡ã確èªããŠãã ããïŒ1719ã1727ãã³ã³ãã€ã©CodeRecognizer.cs 1719
- V3003 ãifïŒAïŒ{...} else ifïŒAïŒ{...}ããã¿ãŒã³ã®äœ¿çšãæ€åºãããŸããã è«çãšã©ãŒãååšããå¯èœæ§ããããŸãã ãã§ãã¯è¡ïŒ1721ã1729ãã³ã³ãã€ã©CodeRecognizer.cs 1721
åé¡ãããæ確ã«ããããã«ãã³ãŒããå°ãåçŽåããŸãã
private void ForEachPrefix(IExpression expr, Action<IExpression> action) { if (....) .... else if (expr is IUnaryExpression) ForEachPrefix(((IUnaryExpression)expr).Expression, action); else if (expr is IAddressReferenceExpression) ForEachPrefix(((IAddressReferenceExpression)expr).Expression, action); .... else if (expr is IUnaryExpression) ForEachPrefix(((IUnaryExpression)expr).Expression, action); else if (expr is IAddressReferenceExpression) ForEachPrefix(((IAddressReferenceExpression)expr).Expression, action) .... }
æ¡ä»¶åŒã¯è€è£œãããè€æ°ã®ifã¹ããŒãã¡ã³ãã®ãã©ã³ããäœæãããŸãã ããããããã®ã³ãŒãã¯ã³ããŒã¢ã³ãããŒã¹ãã¡ãœããã䜿çšããŠèšè¿°ãããŠãããããåé¡ãçºçããŸããã 次ã®çç±ãããéè€ã®ãã©ã³ãã¯å®è¡ãããªãããšãããããŸãã ã
- æ¡ä»¶åŒãçã®å Žå ã察å¿ãããã¢ã®æåã®ifã¹ããŒãã¡ã³ãã®æ¬äœãå®è¡ãããŸãã
- æåã®ã±ãŒã¹ã§æ¡ä»¶åŒãfalseã®å Žåã2çªç®ã®æ¡ä»¶åŒã¯falseã«ãªããŸãã
then-ãã©ã³ãã«ã¯åãã¢ã¯ã·ã§ã³ãå«ãŸããŠãããããä»ã§ã¯çŽããããåé·ã³ãŒãã®ããã«èŠããŸãã ããã¯å¥ã®çš®é¡ã®åé¡ã§ããå¯èœæ§ããããŸã-ãã€ã¯ã§ã¯ãªããä»ã®ãã§ãã¯ãå®è¡ããå¿ èŠããããŸãã
ç¶ããŸãã
public int Compare(Pair<int, int> x, Pair<int, int> y) { if (x.First < y.First) { if (x.Second >= y.Second) { // y strictly contains x return 1; } else { // No containment - order by left bound return 1; } } else if (x.First > y.First) { if (x.Second <= y.Second) { // x strictly contains y return -1; } else { // No containment - order by left bound return -1; } } .... }
PVS-Studioã®èŠå ïŒ
- V3004 ãthenãã¹ããŒãã¡ã³ãã¯ãelseãã¹ããŒãã¡ã³ããšåçã§ãã ã©ã³ã¿ã€ã RegexpTreeBuilder.cs 1080
- V3004 ãthenãã¹ããŒãã¡ã³ãã¯ãelseãã¹ããŒãã¡ã³ããšåçã§ãã ã©ã³ã¿ã€ã RegexpTreeBuilder.cs 1093
ã³ãŒãã«ã¯ã thenãã©ã³ããšelseãã©ã³ãã®åäžã®ããã£ãæã€2ã€ã®æ¡ä»¶ã¹ããŒãã¡ã³ããå«ãŸããŠãããããéåžžã«çãããèŠããŸã ã ã©ã¡ãã®å Žåããããããç°ãªãå€ãè¿ã䟡å€ããããŸãã ãŸãã¯ããããæ³å®ãããåäœã§ããå Žåãåé·ãªæ¡ä»¶ã¹ããŒãã¡ã³ããåé€ãããšäŸ¿å©ã§ãã
èå³æ·±ããµã€ã¯ã«ããããŸããã 以äžã®äŸïŒ
private static Set<StochasticityPattern> IntersectPatterns(IEnumerable<StochasticityPattern> patterns) { Set<StochasticityPattern> result = new Set<StochasticityPattern>(); result.AddRange(patterns); bool changed; do { int count = result.Count; AddIntersections(result); changed = (result.Count != count); break; } while (changed); return result; }
PVS-StudioèŠå ïŒ V3020ã«ãŒãå ã®ç¡æ¡ä»¶ã®ããã¬ãŒã¯ãã ã³ã³ãã€ã©DefaultFactorManager.cs 474
ç¡æ¡ä»¶ã®breakã¹ããŒãã¡ã³ãã«ãããã«ãŒãã1åã ãå®è¡ããã å€æŽãããå¶åŸ¡å€æ°ã¯äœ¿çšãããŸããã äžè¬çã«ãã³ãŒãã¯å¥åŠã§çãããããã«èŠããŸãã
åãã¡ãœããïŒæ£ç¢ºãªã³ããŒïŒãå¥ã®ã¯ã©ã¹ã§èŠã€ãããŸããã 察å¿ããã¢ãã©ã€ã¶ãŒèŠåïŒ V3020ã«ãŒãå ã®ç¡æ¡ä»¶ã®ããã¬ãŒã¯ãã Visualizers.Windows FactorManagerView.cs 350
ãšããã§ãã¡ãœããã¯ã«ãŒãå ã§ç¡æ¡ä»¶ã®continueã¹ããŒãã¡ã³ãã«ééããŸããïŒã¢ãã©ã€ã¶ãŒã¯åã蚺æã§ãããèŠã€ããŸããïŒããããã¯ç¹å¥ãªäžæçãªè§£æ±ºçã§ããããšã確èªããã³ã¡ã³ããäžã«ãããŸããïŒ
// TEMPORARY continue;
ç¡æ¡ä»¶ã®äŒæ©å£°æã®è¿ãã«ãã®ãããªã³ã¡ã³ãããªãã£ãããšãæãåºããŸãã
ç¶ããŸãããã
internal static DependencyInformation GetDependencyInfo(....) { .... IExpression resultIndex = null; .... if (resultIndex != null) { if (parameter.IsDefined( typeof(SkipIfMatchingIndexIsUniformAttribute), false)) { if (resultIndex == null) throw new InferCompilerException( parameter.Name + " has SkipIfMatchingIndexIsUniformAttribute but " + StringUtil.MethodNameToString(method) + " has no resultIndex parameter"); .... } .... } .... }
PVS-Studio èŠå ïŒ V3022åŒ 'resultIndex == null'ã¯åžžã«falseã§ãã ã³ã³ãã€ã©FactorManager.cs 382
ããã«ã宣èšãšäžèšã®æ€èšŒã®éã§ã resultIndexå€æ°ã®å€ãå€ããå¯èœæ§ãããããšã«æ³šæããŠãã ããã ãã ãã resultIndexïŒ= NullãšresultIndex == nullã®ãã§ãã¯ã®éã«ãå€ãå€æŽããããšã¯ã§ããŸããã ãããã£ãŠãåŒresultIndex == nullã®çµæã¯åžžã«falseã«ãªããŸã ãããã¯ãäŸå€ãã¹ããŒãããªãããšãæå³ããŸãã
åé¡ãèŠã€ããããã«ãç§ã®ææ¡ãªãã«èªåã§ãšã©ãŒãèŠã€ããããšã«èå³ãããããšãé¡ã£ãŠããŸããã念ã®ãããããäžåºŠããçŽãããšãææ¡ããŸãã ã¡ãœããã³ãŒãã¯å°ããã®ã§ãå šäœã説æããŸãã
public static Tuple<int, string> ComputeMovieGenre(int offset, string feature) { string[] genres = feature.Split('|'); if (genres.Length < 1 && genres.Length > 3) { throw new ArgumentException(string.Format( "Movies should have between 1 and 3 genres; given {0}.", genres.Length)); } double value = 1.0 / genres.Length; var result = new StringBuilder( string.Format( "{0}:{1}", offset + MovieGenreBuckets[genres[0]], value)); for (int i = 1; i < genres.Length; ++i) { result.Append( string.Format( "|{0}:{1}", offset + MovieGenreBuckets[genres[i].Trim()], value)); } return new Tuple<int, string>(MovieGenreBucketCount, result.ToString()); }
ããã§äœãèµ·ãããèŠãŠã¿ãŸãããã å ¥åæååã¯ãæåã|ãã§è§£æãããŸãã é åã®é·ããæåŸ ã©ããã§ãªãå ŽåãäŸå€ãã¹ããŒããå¿ èŠããããŸãã ã¡ãã£ãšåŸ ã£ãŠ ... genres.Length <1 && genres.Length> 3 ïŒ åŒã«å¿ èŠãªå€ã®ç¯å²ïŒ [int.MinValue..1ïŒãšïŒ3..int.MaxValue] ïŒã®äž¡æ¹ã«ããã«è©²åœããæ°å€ã¯ãªããããåŒã®çµæã¯åžžã«falseã«ãªããŸã ã ãããã£ãŠããã®ãã§ãã¯ã§ã¯äœãä¿è·ããããäºæãããäŸå€ã¯ã¹ããŒãããŸããã
ããã¯ã¢ãã©ã€ã¶ãŒãèŠåãããã®ã§ãïŒ V3022åŒ 'genres.Length <1 && genres.Length> 3'ã¯åžžã«falseã§ãã ãããã '||' ããã§æŒç®åã䜿çšããå¿ èŠããããŸãã Evaluator Features.cs 242
çãããæ žåè£æäœãçºçããŸããã
public static void CreateTrueThetaAndPhi(....) { .... double expectedRepeatOfTopicInDoc = averageDocLength / numUniqueTopicsPerDoc; .... int cnt = Poisson.Sample(expectedRepeatOfTopicInDoc); .... }
PVS-StudioèŠå ïŒ V3041åŒã¯æé»çã« 'int'åãã 'double'åã«ãã£ã¹ããããŸããã åæ°éšåã®æ倱ãé¿ããããã«ãæ瀺çãªåãã£ã¹ãã®äœ¿çšãæ€èšããŠãã ããã äŸïŒdouble A =ïŒdoubleïŒïŒXïŒ/ Y;ã LDA Utilities.cs 74
ããã¯ããã§ã¯çãããïŒæŽæ°é€ç®ãå®è¡ããïŒå€æ°averageDocLengthãšnumUniqueTopicsPerDocã¯intåïŒãçµæã¯doubleåã®å€æ°ã«æžã蟌ãŸããŸãã 質åãè«ãïŒããã¯ç¹å¥ã«è¡ãããã®ãããããšãå®æ°ã®é€ç®ããŸã æ瀺ãããŠããã®ãïŒ å€æ°expectedRepeatOfTopicInDocãintåã§ãã£ãå Žåãããã«ããèãããã質åã解決ãããŸãã
ä»ã®å Žæã§ã¯ãåŒæ°ãçãããå€æ°expectedRepeatOfTopicInDocã§ããPoisson.Sampleã¡ãœããããããšãã°ä»¥äžã§èª¬æããããã«äœ¿çšãããŸãã
int numUniqueWordsPerTopic = Poisson.Sample((double)averageWordsPerTopic);
averageWordsPerTopicã¯intåã§ã䜿çšå Žæã§ãã§ã«doubleã«å€æãããŠããŸãã
ãããŠãããã«å¥ã®äœ¿çšå ŽæããããŸãã
double expectedRepeatOfWordInTopic = ((double)numDocs) * averageDocLength / numUniqueWordsPerTopic; .... int cnt = Poisson.Sample(expectedRepeatOfWordInTopic);
å€æ°ã®ååã¯å ã®äŸãšåãã§ããããšã«æ³šæããŠãã ãããå®æ°ã®é€ç®ã®ã¿ã䜿çšããŠã expectedRepeatOfWordInTopicãåæåããŸãïŒæ瀺çã«numDocsãdoubleã«ãã£ã¹ãããŸã ïŒã
äžè¬ã«ãã¢ãã©ã€ã¶ãŒãèŠåãçºè¡ããéå§å Žæã調ã¹ã䟡å€ããããŸãã
ãããããããä¿®æ£ããå¿ èŠããããã©ãããããã³ã³ãŒãã®äœæè ã«ã¯ã©ã®ããã«ïŒãã£ãšããç¥ã£ãŠããïŒèš±å¯ãããã«ã€ããŠã®èå¯ã¯ãããã«å ã«é²ã¿ãŸãããã 次ã®äžå¯©ãªéšéãžã
public static NonconjugateGaussian BAverageLogarithm(....) { .... double v_opt = 2 / 3 * (Math.Log(mx * mz / Ex2 / 2) - m); if (v_opt != v) { .... } .... }
PVS-StudioèŠå ïŒ V3041åŒã¯æé»çã« 'int'åãã 'double'åã«ãã£ã¹ããããŸããã åæ°éšåã®æ倱ãé¿ããããã«ãæ瀺çãªåãã£ã¹ãã®äœ¿çšãæ€èšããŠãã ããã äŸïŒdouble A =ïŒdoubleïŒïŒXïŒ/ Y;ã ã©ã³ã¿ã€ã ProductExp.cs 137
ã¢ãã©ã€ã¶ãŒã¯ãæŽæ°é€ç®ã®çãããæäœãåã³æ€åºããŸããã 2ãš3ã¯æŽæ°ã®æ°å€ãªãã©ã«ã§ãããåŒ2/3ã®çµæã¯0ã«ãªããŸã ã ãã®çµæãåŒå šäœã¯æ¬¡ã®åœ¢åŒãåããŸãã
double v_opt = 0 * expr;
åæããŸããå°ãå¥åŠã§ãã äœåããã®èŠåã«æ»ããäœããã®ãã£ãããèŠã€ããããšããŠãèšäºã«è¿œå ããããšã¯ããŸããã§ããã ãã®ã¡ãœããã«ã¯æ°åŠãšããŸããŸãªå ¬åŒããããŸãïŒççŽã«èšã£ãŠãç§ã¯æ¬åœã«å解ããããããŸããã§ããïŒã ããã«ããã®èšäºã§æžããèŠåã«ã€ããŠã¯å¯èœãªéãæççã§ãããããããããããç 究ããåŸã«ã®ã¿èª¬æããŸãã
ããããããããç§ã¯å€æãã«ãªããŸãã-ãªã2/3ãšæžããã0ã®åœ¢åŒã®ä¹æ°ãå¿ èŠãªã®ã§ããïŒ ãšã«ãããã®å Žæã¯äžèŠã®äŸ¡å€ããããŸãã
public static void WriteAttribute(TextWriter writer, string name, object defaultValue, object value, Func<object, string> converter = null) { if ( defaultValue == null && value == null || value.Equals(defaultValue)) { return; } string stringValue = converter == null ? value.ToString() : converter(value); writer.Write($"{name}=\"{stringValue}\" "); }
PVS-StudioèŠå ïŒ V3080 nullåç §è§£é€ã®å¯èœæ§ããããŸãã ãå€ãã®æ€æ»ãæ€èšããŠãã ããã ã³ã³ãã€ã©WriteHelpers.cs 78
æ¡ä»¶ã«åºã¥ããã¢ãã©ã€ã¶ãŒã®ããªãå ¬å¹³ãªäž»åŒµã å€== nullã®å ŽåãåŒvalue.EqualsïŒdefaultValueïŒã§nullåç §ã®éåç §ãçºçããå¯èœæ§ããããŸã ã ãã®åŒã¯||æŒç®åã®å³åŽã®ãªãã©ã³ãã§ãããããèšç®ããã«ã¯å·ŠåŽã®ãªãã©ã³ããfalseã§ããå¿ èŠãããããã®ããã«defaultValue \ valueå€æ°ã®å°ãªããšã1ã€ãnullã§ãªãããšã§ååã§ãã ãã®çµæã defaultValueïŒ= Null ãããã³å€== nullã®å Žå ïŒ
- defaultValue == null- > false ;
- defaultValue == null && value == null- > false ; ïŒ å€ã®ãã§ãã¯ã¯è¡ãããŸããã§ããïŒ
- value.EqualsïŒdefaultValueïŒ -> NullReferenceException ã å€ã¯nullã§ãããã ã
åæ§ã®ã±ãŒã¹ãèŠãŠã¿ãŸãããïŒ
public FeatureParameterDistribution( GaussianMatrix traitFeatureWeightDistribution, GaussianArray biasFeatureWeightDistribution) { Debug.Assert( (traitFeatureWeightDistribution == null && biasFeatureWeightDistribution == null) || traitFeatureWeightDistribution.All( w => w != null && w.Count == biasFeatureWeightDistribution.Count), "The provided distributions should be valid and consistent in the number of features."); .... }
PVS-StudioèŠå ïŒ V3080 nullåç §è§£é€ã®å¯èœæ§ããããŸãã ãtraitFeatureWeightDistributionãã®æ€æ»ãæ€èšããŠãã ããã ã¬ã³ã¡ã³ããŒFeatureParameterDistribution.cs 65
äœåãªéšåã¯æšãŠãŠãããŒã«å€ãèšç®ããããã®ããžãã¯ã®ã¿ãæ®ããŸããããã«ãããææ¡ãããããªããŸãã
(traitFeatureWeightDistribution == null && biasFeatureWeightDistribution == null) || traitFeatureWeightDistribution.All( w => w != null && w.Count == biasFeatureWeightDistribution.Count)
åã³ã||ã®å³ãªãã©ã³ã å·Šã®èšç®çµæãfalseã®å Žåã«ã®ã¿èšç®ãããŸã ã traitFeatureWeightDistribution == nullããã³biasFeatureWeightDistributionïŒ= Nullã®å Žåãå«ããå·ŠåŽã®ãªãã©ã³ããfalseã«ããããšãã§ããŸãã 次ã«ã||æŒç®åã®å³åŽã®ãªãã©ã³ããèšç®ããã traitFeatureWeightDistribution.Allã®åŒã³åºãã«ããArgumentNullExceptionãçºçããŸãã
å¥ã®èå³æ·±ãã³ãŒãïŒ
public static double GetQuantile(double probability, double[] quantiles) { .... int n = quantiles.Length; if (quantiles == null) throw new ArgumentNullException(nameof(quantiles)); if (n == 0) throw new ArgumentException("quantiles array is empty", nameof(quantiles)); .... }
PVS-StudioèŠå ïŒ V3095 nullã«å¯ŸããŠæ€èšŒãããåã«ãåäœç¹ããªããžã§ã¯ãã䜿çšãããŸããã è¡ã確èªããŠãã ããïŒ91ã92ãã©ã³ã¿ã€ã OuterQuantiles.cs 91
quantiles.Lengthããããã£ã«æåã«ã¢ã¯ã»ã¹ã ã次ã«å€äœå€ã® null ããã§ãã¯ãããããšã«æ³šæããŠãã ããã ãã®çµæã quantiles == nullã®å Žåãã¡ãœããã¯äŸå€ãã¹ããŒããŸãããå°ãééã£ãŠããŸãã ã©ãããã圌ãã¯å Žæã®è¡ãå°ç¡ãã«ããã
以åã®ãšã©ãŒã®æ€åºã«èªåã§å¯ŸåŠã§ããå Žåã¯ãã³ãŒããŒã1æ¯å ¥ããŠã次ã®æ¹æ³ã§ãšã©ãŒãèŠã€ããŠããã®åæ¥ãç¹°ãè¿ããŠã¿ãããšããå§ãããŸãã å°ãé¢çœãããããã«ãã¡ãœããã³ãŒãå šäœãåŒçšããŸãã
ïŒ ãã«ãµã€ãºãžã®ãªã³ã¯ ïŒ
ããããŸãããããããŸãããããã¯åè«ã§ããïŒãŸãã¯æåããŸãããïŒïŒïŒã ã¿ã¹ã¯ãå°ãç°¡åã«ããŸãããã
if (sample.Precision < 0) { precisionIsBetween = true; lowerBound = -1.0 / v; upperBound = -mean.Precision; } else if (sample.Precision < -mean.Precision) { precisionIsBetween = true; lowerBound = 0; upperBound = -mean.Precision; } else { // in this case, the precision should NOT be in this interval. precisionIsBetween = false; lowerBound = -mean.Precision; lowerBound = -1.0 / v; }
è¯ããªã£ãïŒ ã¢ãã©ã€ã¶ãŒã¯ããã®ã³ãŒãã«å¯ŸããŠæ¬¡ã®èŠåãçºè¡ããŸãããV3008 ãlowerBoundãå€æ°ã«ã¯ãé£ç¶ããŠ2åå€ãå²ãåœãŠãããŸãã ããããããã¯ééãã§ãã è¡ã確èªããŠãã ããïŒ324ã323ãã©ã³ã¿ã€ã GaussianOp.cs 324
å®éãæåŸã®elseãã©ã³ãã§ã¯ã lowerBoundå€æ°ã®å€ãé£ç¶ããŠ2åå²ãåœãŠãããŸãã ã©ãããïŒãããŠäžèšã®ã³ãŒãã§å€æãããšïŒãå€æ°upperBoundã¯å²ãåœãŠã®1ã€ã«é¢äžããŠããå¿ èŠããããŸãã
ããã«ç¶ããŸãã
private void WriteAucMatrix(....) { .... for (int c = 0; c < classLabelCount; c++) { int labelWidth = labels[c].Length; columnWidths[c + 1] = labelWidth > MaxLabelWidth ? MaxLabelWidth : labelWidth; for (int r = 0; r < classLabelCount; r++) { int countWidth = MaxValueWidth; if (countWidth > columnWidths[c + 1]) { columnWidths[c + 1] = countWidth; } } .... }
PVS-StudioèŠå ïŒ V3081 ãrãã«ãŠã³ã¿ãŒã¯ãã¹ããããã«ãŒãå ã§ã¯äœ¿çšãããŸããã ãcãã«ãŠã³ã¿ãŒã®äœ¿çšç¶æ³ã調ã¹ãããšãæ€èšããŠãã ããã CommandLine ClassifierEvaluationModule.cs 459
å åŽã®ã«ãŒãã®ã«ãŠã³ã¿ãŒ-r-ã¯ããã®ã«ãŒãã®æ¬äœã§ã¯äœ¿çšãããªãããšã«æ³šæããŠãã ããã ãã®ãããå åŽã®ã«ãŒãã®ãã¹ãŠã®å埩äžã«ãåãæäœãåãèŠçŽ ã«å¯ŸããŠå®è¡ãããŸããçµå±ãã€ã³ããã¯ã¹ã¯å åŽïŒ r ïŒã§ã¯ãªãå€åŽã®ã«ãŒãïŒ c ïŒã®ã«ãŠã³ã¿ãŒã䜿çšããŸãã
ä»ã«äœãé¢çœããšæãããã®ãèŠãŠã¿ãŸãããã
public RegexpFormattingSettings( bool putOptionalInSquareBrackets, bool showAnyElementAsQuestionMark, bool ignoreElementDistributionDetails, int truncationLength, bool escapeCharacters, bool useLazyQuantifier) { this.PutOptionalInSquareBrackets = putOptionalInSquareBrackets; this.ShowAnyElementAsQuestionMark = showAnyElementAsQuestionMark; this.IgnoreElementDistributionDetails = ignoreElementDistributionDetails; this.TruncationLength = truncationLength; this.EscapeCharacters = escapeCharacters; }
PVS-StudioèŠå ïŒ V3117ã³ã³ã¹ãã©ã¯ã¿ãŒãã©ã¡ãŒã¿ãŒ 'useLazyQuantifier'ã¯äœ¿çšãããŸããã ã©ã³ã¿ã€ã RegexpFormattingSettings.cs 38
ã³ã³ã¹ãã©ã¯ã¿ãŒã¯1ã€ã®ãã©ã¡ãŒã¿ãŒuseLazyQuantifierã䜿çšããŸããã ããã¯ã察å¿ããååãšã¿ã€ããæã€ããããã£ãã¯ã©ã¹-UseLazyQuantifierã§å®çŸ©ãããŠãããšããäºå®ã®èæ¯ã«å¯ŸããŠç¹ã«çãããããã«èŠããŸãã ã©ãããã圌ãã¯å¯Ÿå¿ãããã©ã¡ãŒã¿ãä»ããŠãããåæåããã®ãå¿ããŠããŸããã
ããã€ãã®æœåšçã«å±éºãªã€ãã³ããã³ãã©ã«äŒããŸããã ãããã®1ã€ã®äŸã以äžã«ç€ºããŸãã
public class RecommenderRun { .... public event EventHandler Started; .... public void Execute() { // Report that the run has been started if (this.Started != null) { this.Started(this, EventArgs.Empty); } .... } .... }
PVS-StudioèŠå ïŒ V3083ã€ãã³ã 'Started'ã®å®å šã§ãªãåŒã³åºããNullReferenceExceptionãçºçããå¯èœæ§ããããŸãã ã€ãã³ããåŒã³åºãåã«ãããŒã«ã«å€æ°ã«ã€ãã³ããå²ãåœãŠãããšãæ€èšããŠãã ããã Evaluator RecommendederRun.cs 115
å®éã«ã¯ã nullã®äžçåŒã®ãã§ãã¯ãšãã³ãã©ãŒã®åŒã³åºãã®éã§ãã€ãã³ãã®ãµãã¹ã¯ã©ã€ãã解é€ã§ããŸãããŸãã nullã®ãã§ãã¯ãšãã³ãã©ãŒã®åŒã³åºãã®éã«ã€ãã³ãã«ãµãã¹ã¯ã©ã€ããŒããªãå Žåã NullReferenceExceptionãã¹ããŒãããŸãã ãã®ãããªåé¡ãåé¿ããã«ã¯ãããšãã°ãããªã²ãŒããã§ãŒã³ãžã®ãªã³ã¯ãããŒã«ã«å€æ°ã«ä¿åããããã?.ãæŒç®åã䜿çšããŸã ãã³ãã©ãŒãåŒã³åºããŸãã
äžèšã®ã³ãŒãã¹ããããã«å ããŠããã®ãããªå Žæã35åãããŸããã
ãšããã§ã V3024ã«ã¯785 åã®èŠåããããŸããã æŒç®åãïŒ=ããŸãã¯ã==ãã䜿çšããŠå®æ°ãæ¯èŒãããšãèŠåV3024ãçºè¡ãããŸãã ãã®ãããªæ¯èŒãå¿ ãããæ£ãããªãçç±ã«ã€ããŠã¯ããã§ã¯èª¬æããŸãããããã«ã€ããŠã®è©³çŽ°ã¯ããã¥ã¡ã³ãã«èšèŒãããŠããã StackOverflowãžã®ãªã³ã¯ããããŸãïŒãããããã§ãïŒã
åŒãèšç®ãé »ç¹ã«èŠã€ããããšãèãããšããããã®èŠåã¯éèŠãªå ŽåããããŸãããã¬ãã«3ã«ãªããŸãïŒãã¹ãŠã®ãããžã§ã¯ãã«é¢é£ãããã®ã§ã¯ãªãããïŒã
ãããã®èŠåãç¡é¢ä¿ã§ããããšã確å®ãªå Žåã¯ã ã»ãŒ1åã¯ãªãã¯ããã ãã§ããããåé€ã§ããã¢ãã©ã€ã¶ãŒæäœã®ç·æ°ãåæžã§ããŸã ã
ãããã«
ã©ãããããããç§ã¯é·ãéããããžã§ã¯ãã®ãã§ãã¯ã«é¢ããèšäºãæžããŠããªãã£ãããšããããããã®ããã»ã¹ã«åã³è§Šããããšã¯éåžžã«æ¥œããããšã§ããã ãŸãããã®èšäºããæ°ãã/æçšãªäœããåŠãã ããå°ãªããšãèå³ãæã£ãŠèªãã§ã»ãããšæããŸãã
éçºè ã«åé¡é åã®æ©æä¿®æ£ãæã¿ãééããç¯ãããšã¯æ®éã§ãããç§ãã¡ã¯äººéã§ããããšãæãåºãããŠãã ããã ãã®ããã«ã¯ã人ãèŠéãããã®ãèŠã€ããããã«ãéçã¢ãã©ã€ã¶ãŒãªã©ã®è¿œå ã®ããŒã«ãå¿ èŠã§ãããïŒ ãšã«ãã-ãããžã§ã¯ãã§é 匵ã£ãŠãã ããããããŠä»äºã«æè¬ããŸãïŒ
ãããŠãéçã¢ãã©ã€ã¶ãŒã®æ倧ã®å©ç¹ã¯ã éåžžã®äœ¿çšã§éæãããããšãå¿ããªãã§ãã ããã
æé«ïŒ
ãã®èšäºãè±èªåã®èŽè¡ãšå ±æãããå Žåã¯ã翻蚳ãžã®ãªã³ã¯ã䜿çšããŠãã ããïŒã»ã«ã²ã€ãŽã¡ã·ãªãšãã Infer.NETã³ãŒãã«ã¯ã©ã®ãããªãšã©ãŒãæœãã§ããŸããïŒ