-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix condition in Debug.Assert in TarEntry.cs #100860
Conversation
The precedence of `not` is higher than of `or`, so without parentheses the actual condition was `((not RegularFile) or V7RegularFile or ContigousFile)`, which is not what this function actually expects (see switch cases and the condition in caller function).
Tagging subscribers to this area: @dotnet/area-system-formats-tar |
Similar to previous commit
@@ -424,7 +424,7 @@ private Task ExtractToFileInternalAsync(string filePath, string? linkTargetPath, | |||
|
|||
private void CreateNonRegularFile(string filePath, string? linkTargetPath) | |||
{ | |||
Debug.Assert(EntryType is not TarEntryType.RegularFile or TarEntryType.V7RegularFile or TarEntryType.ContiguousFile); | |||
Debug.Assert(EntryType is not (TarEntryType.RegularFile or TarEntryType.V7RegularFile or TarEntryType.ContiguousFile)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: alternative fix is what we are using in number of places (including this file):
Debug.Assert(EntryType is not (TarEntryType.RegularFile or TarEntryType.V7RegularFile or TarEntryType.ContiguousFile)); | |
Debug.Assert(EntryType is not TarEntryType.RegularFile and not TarEntryType.V7RegularFile or TarEntryType.ContiguousFile); |
Good catch! C# doesn't have There is another instance in the repo: runtime/src/tools/illink/src/linker/Linker/UnconditionalSuppressMessageAttributeState.cs Line 260 in d88c7ba
could you fix it as well while at it? |
I fixed it before you asked (by adding second commit into this pull request). Regarding Debug.Assert (provider isn't ModuleDefinition or AssemblyDefinition); where |
Thanks |
The precedence of
not
is higher than ofor
, so without parentheses the actual condition was((not RegularFile) or V7RegularFile or ContigousFile)
, which is not what this function actually expects (see switch cases and the condition in caller function).The issue was found by Svace static analyzer: https://www.ispras.ru/en/technologies/svace/