Stack error in 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.

I also confirmed that the message I am receiving from the server is less than 200 characters in length.

Environment:
Windows 64bit.
VS 2010

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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();
Does RecvData() put a zero at the end of the array? If not, line 13 will read from who knows where.
Topic archived. No new replies allowed.