Skip to content

Commit

Permalink
Fix infinite loop when iterating flags with invalid input. (#41)
Browse files Browse the repository at this point in the history
Update version for new release.
  • Loading branch information
TylerBrinkley authored Nov 18, 2022
1 parent 54475d4 commit a35664d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

<ItemGroup>
<PackageReference Include="FastEnum" Version="1.5.3" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net45" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net461" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="FastEnum" Version="1.5.3" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net45" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net461" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Diagnostics.FileVersionInfo" Version="4.3.0" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
<ProjectReference Include="..\Enums.NET\Enums.NET.csproj" />
Expand Down
4 changes: 4 additions & 0 deletions Src/Enums.NET.Test/Enums.NET.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net45" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<ProjectReference Include="..\Enums.NET.TestEnums\Enums.NET.TestEnums.csproj" />
Expand Down
27 changes: 27 additions & 0 deletions Src/Enums.NET.Test/Issues/Issue40.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using NUnit.Framework;

namespace EnumsNET.Tests.Issues
{
[TestFixture]
public class Issue40
{
[Test]
public void GetFlags_SuccessfullyEnumerates_WhenUsingLargeCertainEnumValue()
{
CollectionAssert.AreEqual(new[] { MyEnum.Val1, MyEnum.Val40 }, ((MyEnum)1610612801).GetFlags());
}

[Flags]
public enum MyEnum
{
Unknown = 0x0,
Val1 = 0x1,
Val4 = 0x4,
Val8 = 0x8,
Val10 = 0x10,
Val40 = 0x40,
Val80 = 0x80,
}
}
}
4 changes: 4 additions & 0 deletions Src/Enums.NET.TestEnums/Enums.NET.TestEnums.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<ItemGroup>
<ProjectReference Include="..\Enums.NET\Enums.NET.csproj" />
<Folder Include="Properties\" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net45" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator></Generator>
</EmbeddedResource>
Expand Down
2 changes: 1 addition & 1 deletion Src/Enums.NET/EnumCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ private IEnumerable<EnumMemberInternal<TUnderlying, TUnderlyingOperations>> Enum
TUnderlyingOperations operations = default;
var validValue = operations.And(value, _allFlags);
var checkForZero = operations.LessThan(validValue, default) || operations.LessThan(operations.LeftShift(validValue, 1), validValue);
for (var currentValue = operations.One; checkForZero ? !currentValue.Equals(default) : !operations.LessThan(value, currentValue); currentValue = operations.LeftShift(currentValue, 1))
for (var currentValue = operations.One; checkForZero ? !currentValue.Equals(default) : !operations.LessThan(validValue, currentValue); currentValue = operations.LeftShift(currentValue, 1))
{
if (HasAnyFlags(validValue, currentValue))
{
Expand Down
10 changes: 7 additions & 3 deletions Src/Enums.NET/Enums.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<PropertyGroup>
<TargetFrameworks>net45;netcoreapp3.0;netstandard2.1;netstandard2.0;netstandard1.3;netstandard1.1;netstandard1.0</TargetFrameworks>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<FileVersion>4.0.0</FileVersion>
<VersionPrefix>4.0.0</VersionPrefix>
<FileVersion>4.0.1</FileVersion>
<VersionPrefix>4.0.1</VersionPrefix>
<VersionSufix></VersionSufix>
<PackageVersion>4.0.0</PackageVersion>
<PackageVersion>4.0.1</PackageVersion>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Tyler Brinkley</Authors>
<Description>Enums.NET is a high-performance type-safe .NET enum utility library</Description>
Expand All @@ -29,6 +29,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net45" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

Expand Down

0 comments on commit a35664d

Please sign in to comment.