Thread: Strange crash.....

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    76

    Strange crash.....

    This is really a network (ing) program but I belive this happens in the other C++ code.


    azjherben.org/usr.exe


    I'll upload source code soon.
    There isn't alot in the "int main()" section but there are huge headers and classes.



    Idea use of that program (linked above):
    Type in anything first even 'anything'.

    Then try "bob" or "home" as pages.
    Anything else will get a "Page not found" error.

    After a few pages you'll probally not be able to connect anymore;
    My host program will have crashed.



    _____________________
    I don't really need (or expect) you to download and use the programs, but they are there.
    _____________________

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Have you tried using a debugger to see where the crash occured?

  3. #3
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Some of us are not going to download executables. Further, some of us don't run your operating system. Feed us source code.
    Have you corrected the issues expressed in your thread on the networking forum?
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    76
    I know, maybe afraid of virus(es) or something.
    I understand (ed) that.
    (Also I am not running the hosting program, [you'd just get "no server found"])

    Well I belive maybe I have an attempt somewhere that is trying to put a quote...
    (like "Hi it is Bob Saget.")
    That is to big or small into a char.

    Like:
    char bob[5] = "Wow this is big";


    I have had a crash related to that kind of thing before.
    Even though I tried to look out for possible instances of it.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    There are a few hundred possible reasons for your program to crash. Try a debugger.

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    76
    Debugger? Like in the IDE?

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Sure.

  8. #8
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by azjherben View Post
    I know, maybe afraid of virus(es) or something.
    More like I'm too lazy to boot Vista. Takes too long to start. (Although now that I'm discovering the joys of virtualization...)

    Quote Originally Posted by azjherben View Post
    Well I belive maybe I have an attempt somewhere that is trying to put a quote...
    (like "Hi it is Bob Saget.")
    That is to big or small into a char.

    Like:
    char bob[5] = "Wow this is big";
    Did you fix your code from the suggestions on the Network board? This segment, specifically:
    Code:
    // Display message from server
    char buffer[1000];
    memset(buffer,0,999);
    int inDataLength=recv(Socket,buffer,1000,0);
    std::cout<<buffer;
    First, why do you not zero that last byte?
    Second, say I send you more than 1000 characters. recv() will stuff 1000 of them in your buffer, filling it. Then we pass it to std::cout, which requires that the buffer be zero-terminated. However, if I send you 1000 'X', then your buffer is not zero terminated, and you'll get a buffer overflow. (And likely a crash.)

    Instead, zero that last byte: (And leave room for that zero.)
    Code:
    char buffer[1000];
    int inDataLength = recv(Socket, buffer, 999, 0);
    if(inDataLength <= 0)
    {
    	// Handle error / disconnect.
    }
    else
    {
    	buffer[inDataLength] = '\0';
    	std::cout << buffer;
    }
    ...but we're still not there. TCP sockets model a stream. Therefore, there are no 'packets'. If you want a packet, you have to build that yourself - either with some sort of "here's where a packet starts/stops" marker (newline, \0, etc.), or prefix packets with a length. (The latter is more robust in my opinion, and has the advantage that after so many bytes you know how big of a buffer you need.)

    Also, you cannot assume that everything will come in one recv(). For one, what if I sent a string of length 2000? Or, what if I sent a string of length 500, but TCP broke the string apart into two pieces during transport, and the second piece was slower than the first? (You would get the second piece on the next call to recv() if it hadn't arrived yet.)
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  9. #9
    Registered User
    Join Date
    Mar 2009
    Posts
    76
    Thanks for help, but,

    My biggest problem now is how to make it so my users do NOT have to port foward to use this program.



    Also the program runs on windows XP and ME. (and vista)
    Last edited by azjherben; 05-20-2009 at 08:26 PM.

  10. #10
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    You'll have to use UPnP, assuming your user's router supports it.

  11. #11
    Registered User
    Join Date
    Mar 2009
    Posts
    76
    We arn't talking about those cables that you plug into your TV. Right?

  12. #12
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229

  13. #13
    Registered User
    Join Date
    Mar 2009
    Posts
    76
    I googled before I posted btw.
    Lol, lmgtfy.

  14. #14
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by azjherben View Post
    My biggest problem now is how to make it so my users do NOT have to port foward to use this program.
    Port forwarding is only required for the server in a TCP setup. When a client using TCP attempt to connect, it initiates the connection - something that a router doing NAT notices, and can take into account, and route the server's response to the connect back to the proper place.
    As mentioned, there are some other ways around NAT, such as uPnP, if your router supports it. (I know mine doesn't, unfortunately.)

    However, this thread is entitled "strange crash" - uPnP / port forwarding will not fix strange crashes.

    Quote Originally Posted by azjherben View Post
    Also the program runs on windows XP and ME. (and vista)
    2k isn't support though? (;-) kidding)
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange strcpy crash
    By knirirr in forum Windows Programming
    Replies: 5
    Last Post: 07-10-2008, 02:12 AM
  2. Can not debug a crash
    By hannibar in forum Windows Programming
    Replies: 2
    Last Post: 06-30-2007, 10:02 AM
  3. Strange results using dnsapi and windns
    By Niara in forum Networking/Device Communication
    Replies: 3
    Last Post: 08-13-2005, 10:21 AM
  4. Dynamic array sizing causes crash
    By Mithoric in forum C++ Programming
    Replies: 3
    Last Post: 12-30-2003, 07:46 AM
  5. FYI: asctime(gmtime(&mytime)) = crash!
    By anonytmouse in forum C Programming
    Replies: 2
    Last Post: 09-29-2003, 02:24 AM