Thread: stack error for a char array

  1. #1
    Registered User
    Join Date
    May 2010

    stack error for a char array


    I have a socket client running which has a char array of size 512 mentioned. I have a loop to receive the message from the server, when the loop exits I am getting the following error.

    Windows 64bit.
    VS 2010

    Run-Time check failure #2 - Stack around the variable 'recMessage' was corrupted.

    int STRLEN = 512;
    char recMessage[STRLEN] = "0";
    ClientSocket sockClient;
    sockClient.ConnectToServer( ipAddress.c_str(), port );
    sockClient.RecvData( recMessage, STRLEN );
    int counter = 0
    while(counter <= 10){
    	sockClient.RecvData( recMessage, STRLEN );
    	cout << recMessage << endl;

  2. #2
    Registered User
    Join Date
    May 2010
    just wanted to confirm that the message I am receiving from the server is less than 200 characters.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    You would need to post the code for sockClient.RecvData as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Join Date
    Oct 2007
    Inside my computer
    int STRLEN = 512;
    char recMessage[STRLEN] = "0";
    This is not valid C++ code.

    Also, the error message says you have a buffer overrun.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-17-2008, 12:36 PM
  2. Compiler error due to char array
    By Godders_2k in forum C Programming
    Replies: 13
    Last Post: 11-09-2007, 07:04 AM
  3. Char array display error...
    By Karpaty in forum C Programming
    Replies: 23
    Last Post: 10-31-2007, 07:17 AM
  4. signed char array to unsign char array.
    By beon in forum C Programming
    Replies: 5
    Last Post: 12-14-2006, 07:19 PM
  5. error converting string to char array
    By COBOL2C++ in forum C++ Programming
    Replies: 6
    Last Post: 07-11-2003, 10:59 AM