Skip to content

JSSignatureContext.cs may include incorrect use of Math.Abs #84996

@tfenise

Description

@tfenise

// there could be multiple method signatures with the same name, get unique signature name
uint hash = 17;
unchecked
{
foreach (var param in sigContext.ElementTypeInformation)
{
hash = hash * 31 + (uint)param.ManagedType.FullTypeName.GetHashCode();
}
};
int typesHash = Math.Abs((int)hash);

The last line does not seem correct. If (int)hash == int.MinValue, Math.Abs would throw, which I suppose is not the intended behaviour for a hash function. I would suggest simply int typesHash = (int)hash & int.MaxValue;, or if the hash code is required to be persistent across versions, int typesHash = (int)hash == int.MinValue ? int.MaxValue : Math.Abs((int)hash).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions