captchaman
Junior Member
- Sep 16, 2010
- 192
- 848
I'm trying to convert the Google PR checksum algorithm from C# to VB.NET, the converter has done what it can but I'm doing the rest manually. Here's the error dump:
Here's the code that causes the crash:
The offending code is
(Last part in the a calculation)
Here's the same code (from the original working source) in C#:
So, what's the deal? I've been trying to fix it but to no avail.
Code:
System.OverflowException was unhandled
Message=Arithmetic operation resulted in an overflow.
Source=WindowsApplication4
StackTrace:
at WindowsApplication4.Form1.Crashit() in C:\Users\rx\AppData\Local\Temporary Projects\WindowsApplication4\Form1.vb:line 11
at WindowsApplication4.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\rx\AppData\Local\Temporary Projects\WindowsApplication4\Form1.vb:line 24
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication4.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Code:
Function Crashit()
Dim a As UInteger, b As UInteger
Dim k As Integer = 0
a = InlineAssignHelper(b, &H9E3779B9UI)
Dim URL As String = "info:google.com"
Dim length As Integer = URL.Length
While length >= 12
a += CUInt(AscW(URL(k + 0))) + CUInt(AscW(URL(k + 1)) << 8) + CUInt(AscW(URL(k + 2)) << 16) + CUInt(AscW(URL(k + 3)) << 24)
End While
End Function
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, value As T) As T
target = value
Return value
End Function
Code:
CUInt(AscW(URL(k + 3)) << 24)
Here's the same code (from the original working source) in C#:
Code:
uint a, b;
a = b = 0x9E3779B9;
int k = 0;
string URL = "info:google.com";
int length = URL.Length;
while (length >= 12)
{
a += (uint)(URL[k + 0] + (URL[k + 1] << 8) + (URL[k + 2] << 16) + (URL[k + 3] << 24));
}