stack error for a char array

This is a discussion on stack error for a char array within the C++ Programming forums, part of the General Programming Boards category; Hi: I have a socket client running which has a char array of size 512 mentioned. I have a loop ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    14

    stack error for a char array

    Hi:

    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.

    Environment:
    Windows 64bit.
    VS 2010

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

    Code:
    int STRLEN = 512;
    char recMessage[STRLEN] = "0";
    ClientSocket sockClient;
    
    sockClient.ConnectToServer( ipAddress.c_str(), port );
    sockClient.SendData("L|100=some_value;101=some_value\n");
    sockClient.RecvData( recMessage, STRLEN );
    
    int counter = 0
    while(counter <= 10){
    
    	sockClient.RecvData( recMessage, STRLEN );
    	cout << recMessage << endl;
    	counter++;
    }
    
    memset(recMessage,0,sizeof(char)*STRLEN);
    sockClient.CloseConnection();

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

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,173
    Code:
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-17-2008, 11:36 AM
  2. Compiler error due to char array
    By Godders_2k in forum C Programming
    Replies: 13
    Last Post: 11-09-2007, 06: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, 06: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21