diff options
author | jfrijters <jfrijters> | 2010-07-28 16:12:47 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2010-07-28 16:12:47 +0400 |
commit | 27703d02f71109c3b550ca8d77d183264e2ab56a (patch) | |
tree | 5dd1d11ac73315555b0b2d8fd4bbaa904487fb00 /reflect/Writer | |
parent | 096b3adce81ddf5f47c72c483e8fb058d04943de (diff) |
Fix for bug #3035831.
Diffstat (limited to 'reflect/Writer')
-rw-r--r-- | reflect/Writer/VersionInfo.cs | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/reflect/Writer/VersionInfo.cs b/reflect/Writer/VersionInfo.cs index 919a1601..bfcc00b9 100644 --- a/reflect/Writer/VersionInfo.cs +++ b/reflect/Writer/VersionInfo.cs @@ -118,19 +118,19 @@ namespace IKVM.Reflection.Writer lcid = new CultureInfo(culture).LCID; } - Version filever = new Version(fileVersion); + Version filever = ParseVersionRobust(fileVersion); int fileVersionMajor = filever.Major; int fileVersionMinor = filever.Minor; int fileVersionBuild = filever.Build; int fileVersionRevision = filever.Revision; - int productVersionMajor = 0; - int productVersionMinor = 0; - int productVersionBuild = 0; - int productVersionRevision = 0; + int productVersionMajor = fileVersionMajor; + int productVersionMinor = fileVersionMinor; + int productVersionBuild = fileVersionBuild; + int productVersionRevision = fileVersionRevision; if (informationalVersion != null) { - Version productver = new Version(informationalVersion); + Version productver = ParseVersionRobust(informationalVersion); productVersionMajor = productver.Major; productVersionMinor = productver.Minor; productVersionBuild = productver.Build; @@ -241,5 +241,40 @@ namespace IKVM.Reflection.Writer bb.Write((short)(savedPos - pos)); bb.Position = savedPos; } + + private static Version ParseVersionRobust(string ver) + { + int index = 0; + ushort major = ParseVersionPart(ver, ref index); + ushort minor = ParseVersionPart(ver, ref index); + ushort build = ParseVersionPart(ver, ref index); + ushort revision = ParseVersionPart(ver, ref index); + return new Version(major, minor, build, revision); + } + + private static ushort ParseVersionPart(string str, ref int pos) + { + ushort value = 0; + while (pos < str.Length) + { + char c = str[pos]; + if (c == '.') + { + pos++; + break; + } + else if (c >= '0' && c <= '9') + { + value *= 10; + value += (ushort)(c - '0'); + pos++; + } + else + { + break; + } + } + return value; + } } } |