runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Suspicious fragments found by PVS-Studio Static Analyzer

Open VasilievSerg opened this issue 4 years ago • 5 comments

Description

Hello!

I checked the code of .NET libraries (branch 6.0.0) with PVS-Studio and found some suspicious places. I described them in this article in detail.

In the article, each warning has a description, the file and code lines that triggered the analyzer. Last time I described suspicious places in the same format - as I understand it, it is acceptable. :)

Last time some of the described places were fixed, but they weren't mentioned in the issue. :( Is it possible to mention what fixes were made in this issue or somewhere else this time?

Reproduction Steps

Expected behavior

Actual behavior

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

VasilievSerg avatar Dec 27 '21 15:12 VasilievSerg

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

ghost avatar Dec 27 '21 15:12 ghost

Tagging subscribers to this area: @dotnet/area-meta See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Hello!

I checked the code of .NET libraries (branch 6.0.0) with PVS-Studio and found some suspicious places. I described them in this article in detail.

In the article, each warning has a description, the file and code lines that triggered the analyzer. Last time I described suspicious places in the same format - as I understand it, it is acceptable. :)

Last time some of the described places were fixed, but they weren't mentioned in the issue. :( Is it possible to mention what fixes were made in this issue or somewhere else this time?

Reproduction Steps

Expected behavior

Actual behavior

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: VasilievSerg
Assignees: -
Labels:

area-Meta, untriaged

Milestone: -

ghost avatar Dec 28 '21 18:12 ghost

Thanks for sharing. In the future, please open individual Issues; it’s not practical to track all of these via an article that isn’t part of dotnet/runtime, that doesn't let Issues be commented on and closed separately, that tracks possible issues across many different libraries, etc.

Issue 1 False positive. SmallestSize was added after .NET Standard 2.0 and .NET Framework 4.6.1, which this library targets. It could in theory special-case NetCoreAppCurrent to change the compression level for that build, but it’s not clear that provides meaningful enough value.

Issue 2 A PR for this was already opened at https://github.com/dotnet/runtime/pull/63150.

Issue 3 False positive. While maybe not the cleanest code, the extra ctor argument is there to avoid ambiguities with other ctors.

Issue 4 PR: https://github.com/dotnet/runtime/pull/63344

Issue 5 False positive. byte is a built-in primitive; it will not resolve to null.

Issue 6 PR: https://github.com/dotnet/runtime/pull/63343

Issue 7 False positive. While the “OrDefault” is gratuitous, the index will be in range.

Issue 8 This was already found and fixed months ago in https://github.com/dotnet/runtime/pull/57398.

Issue 9, 10, 11, 12 PR: https://github.com/dotnet/runtime/pull/63341

Issue 13 PR: https://github.com/dotnet/runtime/pull/63342. This is debug-only tracing that’s not built into any release binaries, but I fixed it anyway.

Issue 14 This was already found and fixed months ago in https://github.com/dotnet/runtime/pull/60176.

stephentoub avatar Jan 04 '22 15:01 stephentoub

Hello Stephen, Thank you for the feedback on each issue.

In the future, please open individual Issues

OK, no problems.

Anyway, I hope that the article was useful. :) And thank you again for the explanations and fixes!

VasilievSerg avatar Jan 05 '22 08:01 VasilievSerg

Anyway, I hope that the article was useful. :) And thank you again for the explanations and fixes!

Indeed it was, @VasilievSerg. Thanks!

jeffhandley avatar Jan 05 '22 20:01 jeffhandley