Thread: Array bounds overflow

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    13

    Array bounds overflow

    hey im getting an array bounds overflow....

    Code:
    		 if (command == 1)
    			{
    					char outMessage[1] = "1";
    					nBytes = send(mySocket, outMessage, sizeof(outMessage), 0);
    					printf("Message Sent : %s\n", outMessage);	
    			}
    any help would be greatly appreciated.

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    101
    >>char outMessage[1] = "1";
    The array size must be at least 2 to account for the null character implicit in string literals.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    13
    Thanks man i completely forgot about that. Damn short term memory. I cant try it now but im sure thats the problem.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So just say
    char outMessage[] = "1";
    and let the compiler do the counting for you
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  3. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  4. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  5. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM