Re: memcpy junk at beginning of buffer



Test program w/malloc this time produces similiar results.
compiler g++ gcc version 4.0.2 20051125 (Red Hat 4.0.2-8)
Fedora Core 4


#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "Packet.h"

int main()
{
char out[] = "buffer data";

COMMAND *com;
com = (COMMAND *)malloc( sizeof(COMMAND) );
strcpy(com->command,out);

printf("\tCom send: %s\n",com->command);

int len = sizeof(COMMAND);
unsigned char buf[300];

memcpy(&buf[0],(unsigned char *)&com,len);
printf("COM SENDING: <%s>\n",com->command);
printf("COM buf: <%s>\n",buf);

return 0;
}

.



Relevant Pages