diff options
author | Aaron Bockover <abock@xamarin.com> | 2014-01-10 23:13:02 +0400 |
---|---|---|
committer | Aaron Bockover <abock@xamarin.com> | 2014-01-10 23:13:02 +0400 |
commit | bc6da57cc10a5abfa18625f5227771c8faa08707 (patch) | |
tree | ed32a18dc2843bb85c2d63c2c79f4196a590fc17 /mcs | |
parent | 319f562ca781f79ac64b5f9d0edc928ba05e462c (diff) |
mono-api-info: avoid NumberOverflow
GetFlaggedEnumValue converts values to Int64 which
can cause a NumberOverflow exception when the value
is too large to fit (e.g. a large UInt64). Special
case UInt64 values for now (duplicates the logic,
which sucks).
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/tools/corcompare/mono-api-info.cs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/mcs/tools/corcompare/mono-api-info.cs b/mcs/tools/corcompare/mono-api-info.cs index 72c6da574e7..2dc4bcebb3d 100644 --- a/mcs/tools/corcompare/mono-api-info.cs +++ b/mcs/tools/corcompare/mono-api-info.cs @@ -1231,6 +1231,9 @@ namespace CorCompare static object GetFlaggedEnumValue (TypeDefinition type, object value) { + if (value is ulong) + return GetFlaggedEnumValue (type, (ulong)value); + long flags = Convert.ToInt64 (value); var signature = new StringBuilder (); @@ -1257,6 +1260,33 @@ namespace CorCompare return signature.ToString (); } + static object GetFlaggedEnumValue (TypeDefinition type, ulong flags) + { + var signature = new StringBuilder (); + + for (int i = type.Fields.Count - 1; i >= 0; i--) { + FieldDefinition field = type.Fields [i]; + + if (!field.HasConstant) + continue; + + ulong flag = Convert.ToUInt64 (field.Constant); + + if (flag == 0) + continue; + + if ((flags & flag) == flag) { + if (signature.Length != 0) + signature.Append (", "); + + signature.Append (field.Name); + flags -= flag; + } + } + + return signature.ToString (); + } + static object GetEnumValue (TypeDefinition type, object value) { foreach (FieldDefinition field in type.Fields) { |