Click here to Skip to main content
15,886,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote a program for sending file use udt.sdk.4.7a.win32 but when I run it,a error message had occurred:
"A buffer overrun has occurred in udtreceivefile.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.
For more details please see Help topic 'How to debug Buffer Overrun Issues'"
And it stops at: _debugger_hook_dummy = 0 in this method:
void __cdecl _CRT_DEBUGGER_HOOK(int _Reserved)
{
  /* assign 0 to _debugger_hook_dummy so that the function is not folded in retail */
  (_Reserved);
  _debugger_hook_dummy = 0;
}


Please help me to solve it.
Posted
Updated 11-Nov-10 23:21pm
v2

You've given us nothing to go on. How about a call stack for starters...
 
 
Share this answer
 
v2
Try to run aplication step by step (debug). You will get the line number in your code, where error occures. And then thy to check arguments of functions.
 
Share this answer
 
please show your source code ..
 
Share this answer
 
Ok.
My udtsendfile:
// udtsendfile.cpp : main project file.


#include "stdafx.h"
#include<iostream>
#include<udt.h>
#include<string.h>
#include<fstream>
#include<stdio.h>
using namespace std;
using namespace System;
using namespace System::Text;


int main()
{ 
 

   // use this function to initialize the UDT library
   UDT::startup();

   UDTSOCKET serv = UDT::socket(AF_INET, SOCK_STREAM, 0);

   int port = 9000;
   sockaddr_in my_addr;
   my_addr.sin_family = AF_INET;
   my_addr.sin_port = htons(9000);
   memset(&(my_addr.sin_zero), '\0', 8);

   if (UDT::ERROR == UDT::bind(serv, (sockaddr*)&my_addr, sizeof(my_addr)))
   {
      cout << "bind: " << UDT::getlasterror().getErrorMessage() << endl;
      return 0;
   
   }
   cout << "server is ready at port: " << port << endl;

   UDT::listen(serv, 10);

   sockaddr_in their_addr;
   int namelen = sizeof(their_addr);

   UDTSOCKET fhandle;

   if (UDT::INVALID_SOCK == (fhandle = UDT::accept(serv, (sockaddr*)&their_addr, &namelen)))
   {
      cout << "accept: " << UDT::getlasterror().getErrorMessage() << endl;
      return 0;
   }

    UDT::close(serv);

   // aquiring file name information from client
   char file[1024];
   int len;



   if (UDT::ERROR == UDT::recv(fhandle, (char*)&len, sizeof(int), 0))
   {
      cout << "recv: " << UDT::getlasterror().getErrorMessage() << endl;
      return 0;
   }



   if (UDT::ERROR == UDT::recv(fhandle, file, len, 0))
   {
      cout << "recv: " << UDT::getlasterror().getErrorMessage() << endl;
      return 0;
   }
   file[len] = '\0';

   // open the file
   fstream ifs(file, ios::in | ios::binary);

   ifs.seekg(0, ios::end);
   int64_t size = ifs.tellg();
   ifs.seekg(0, ios::beg);

   // send file size information
   if (UDT::ERROR == UDT::send(fhandle, (char*)&size, sizeof(int64_t), 0))
   {
      cout << "send: " << UDT::getlasterror().getErrorMessage() << endl;
      return 0;
   }

   UDT::TRACEINFO trace;
   UDT::perfmon(fhandle, &trace);

   // send the file
   if (UDT::ERROR == UDT::sendfile(fhandle, ifs, 0, size))
   {
      cout << "sendfile: " << UDT::getlasterror().getErrorMessage() << endl;
      return 0;
   }

   UDT::perfmon(fhandle, &trace);
   cout << "speed = " << trace.mbpsSendRate << "Mbits/sec" << endl;

   UDT::close(fhandle);

   ifs.close();

   // use this function to release the UDT library
   UDT::cleanup();

   return 1;
  
}



And my receivefile:
// udtreceivefile.cpp : main project file.


#include "stdafx.h"
#include<iostream>
#include<udt.h>
#include<string.h>
#include<fstream>
#include<stdio.h>
using namespace std;
using namespace System;

int main()
{
 

   // use this function to initialize the UDT library
   UDT::startup();

   UDTSOCKET fhandle = UDT::socket(AF_INET, SOCK_STREAM, 0);

   sockaddr_in serv_addr;
   serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(9000);

    serv_addr.sin_addr.S_un.S_un_b.s_b1=127;
    serv_addr.sin_addr.S_un.S_un_b.s_b2=0;
    serv_addr.sin_addr.S_un.S_un_b.s_b3=0;
    serv_addr.sin_addr.S_un.S_un_b.s_b4=1;
    memset(&(serv_addr.sin_zero), '\0', 8);

   if (UDT::ERROR == UDT::connect(fhandle, (sockaddr*)&serv_addr, sizeof(serv_addr)))
   {
      cout << "connect: " << UDT::getlasterror().getErrorMessage() << endl;
      return 0;
   }

   // send name information of the requested file
   char filepath[]="C:\\t.txt";
   int len = strlen(filepath);

   if (UDT::ERROR == UDT::send(fhandle, (char*)&len, sizeof(int), 0))
   {
      cout << "send: " << UDT::getlasterror().getErrorMessage() << endl;
      return 0;
   }

    if (UDT::ERROR == UDT::send(fhandle, filepath, len, 0))
   {
      cout << "send: " << UDT::getlasterror().getErrorMessage() << endl;
      return 0;
   }

   // get size information
   int64_t size;

   if (UDT::ERROR == UDT::recv(fhandle, (char*)&size, sizeof(int64_t), 0))
   {
      cout << "send: " << UDT::getlasterror().getErrorMessage() << endl;
      return 0;
   }

   // receive the file
   char filenamen[]="t.txt";
   fstream ofs("t.txt", ios::out | ios::binary | ios::trunc);
   int64_t recvsize; 

   if (UDT::ERROR == (recvsize = UDT::recvfile(fhandle, ofs, 0, size)))
   {
      cout << "recvfile: " << UDT::getlasterror().getErrorMessage() << endl;
      return 0;
   }

   UDT::close(fhandle);

   ofs.close();

   // use this function to release the UDT library
   UDT::cleanup();

   return 1;
}
 
Share this answer
 
I tried to run it. When I compiler source code of udt.sdk.4.7a.win32, I set agurment and a similar error had occured.
 
Share this answer
 
Add /RTCs switch to the compiler. This will enable detection of buffer overruns and underruns at runtime. When overrun will be detected, program will break exactly in place where it happened rather than giving you postmortem message.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900