Skip to content

Commit

Permalink
Suppress CA2022 warnings in VB code
Browse files Browse the repository at this point in the history
These warnings are helpful in general. They flag apparently incorrect use of `Stream.Read`, where the return value is unused. In the abstract, reading from a stream into a buffer is not guaranteed to return all the bytes requested, as those bytes may not yet be available.

The cases covered by these three diagnostics are all in very old VB code, which hasn't been touched in ~15 years. My investigation suggests that all usages operate on `MemoryStream` which will actually always return the bytes you request.

I feel it's less risky to just suppress these warnings rather than trying to fix them.
  • Loading branch information
drewnoakes committed Oct 29, 2024
1 parent 78dcae0 commit 065ae1e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Microsoft.VisualStudio.Editors/GlobalSuppressions.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1295,3 +1295,6 @@ Imports System.Diagnostics.CodeAnalysis
' Bugs
<Assembly: SuppressMessage("Style", "IDE0070:Use 'System.HashCode'", Justification:="https://github.com/dotnet/roslyn/issues/45995", Scope:="member", Target:="~M:Microsoft.VisualStudio.Editors.PropertyPages.WPF.ApplicationPropPageVBWPF.StartupObject.GetHashCode~System.Int32")>

<Assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification:="Code has worked for decades. Source is MemoryStream, which will always provide complete result.", Scope:="member", Target:="~M:Microsoft.VisualStudio.Editors.ResourceEditor.Utility.IsWavSoundFile(System.IO.Stream)~System.Boolean")>
<Assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification:="Code has worked for decades. Source is MemoryStream, which will always provide complete result.", Scope:="member", Target:="~M:Microsoft.VisualStudio.Editors.ResourceEditor.ResourceTypeEditorInternalBase.SaveFileFromManifestResource(System.String,System.String)")>
<Assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification:="Code has worked for decades. Source is MemoryStream, which will always provide complete result.", Scope:="member", Target:="~M:Microsoft.VisualStudio.Editors.ResourceEditor.ResourceEditorView.GetFileListFromVsHDropHandle(System.IO.Stream)~Microsoft.VisualStudio.Editors.ResourceEditor.ResourceEditorView.DraggedFileInfo[]")>

0 comments on commit 065ae1e

Please sign in to comment.