memcpy junk at beginning of buffer



Im trying to memcpy a buffer from a filled in simple structure.
When I memcpy and then print the resulting buffer, I see 7 locations
that have junk before my data starts. My data structure is:

struct command_pkt {
char command_num[3];
char command[100];
};

typedef command_pkt COMMAND;

The relevant portion is the following:

sprintf(tmp,"%s %s",ip,host);

COMMAND *com;
strcpy(com->command_num,"1");
strcpy(com->command,tmp);

int len = sizeof(COMMAND);
unsigned char buf[200];
if (len > 200) {
printf("ERROR - len > buf\n");
return -1;
}

memset(&buf[0],0,200);
memcpy(&buf[1],(unsigned char *)&com,len);

printf("COM buf: <%s>\n",buf);

Any ideas why there is junk at the beginning of my buffer?

.



Relevant Pages

  • Re: VC 2003, WinXP and Win2000
    ... issue does not seen to occur at all under Win2k SP4. ... I am working with the wincrypt, and allocating a buffer to hold some ... first-chance exception under WinXP. ... memcpy() line to the following: ...
    (microsoft.public.vc.language)
  • Re: memcpy junk at beginning of buffer
    ... > Im trying to memcpy a buffer from a filled in simple structure. ... > typedef command_pkt COMMAND; ... i.e., you not allocated memory for a COMMAND, and pointed com to that ...
    (comp.lang.c)
  • Re: Efficient scather-gather-copy
    ... memcpythan external programs. ... I can't see that memcpy() would buy you much here, ... passes through the buffer: one to count the newlines and one to ... char *xlate (char *src, size_t len) ...
    (comp.lang.asm.x86)
  • Re: How to disable _SECURE_ATL macro
    ... deprecating memcpy in favor of ... > the problem with memcpy is that if you are interacting with code that you ... clearly defines the size of the buffer accessed. ... is about Secure SCL which most definitely is not "much safer". ...
    (microsoft.public.dotnet.languages.vc)
  • Q: maximizing sequential file read performance
    ... many times above memcpy, and not many times below hardware ... disk IO speed. ... progressivly increase buffer size. ... read the first block from disk into memory, ...
    (comp.os.linux.development.system)