Re: Problem with VS and memcpy...
- From: "Paolo" <paomic@xxxxxxxxx>
- Date: 29 Jun 2006 02:27:25 -0700
Yes I amde some mistakes in the code, I couldn't paste because it was
too long.
Yes, the correct lines are
unsigned char* buffer = new unsigned char[1000];
and
memcpy(buf, temp, sizeof temp);
I didn't use the redundant casts at first, but then I added them, but
nothing changed.
The problem isI just can't see why if I use the debugger before the
memcpy I can see something like
buffer = 0x01234456 "yqhsfjkvdfdsfhfe"
Where "yqhsfjkvdfdsfhfe" ius the content of the buffer, but after
thememcpy it becomes
buffer = 0x01234456 ""
Is it normal?
Tom Widmer [VC++ MVP] ha scritto:
Paolo wrote:
Hi all!
I have a problem with memcpy, or with VS, or both, I'm not sure....
First of all here's my code:
Well, it looks like a high-error-rate copy of it to me, not the original
code.
unsigned char[] buffer = new unsigned char[1000];
That's not legal code. I assume you actually have:
unsigned char* buffer = new unsigned char[1000];
....
Modify(buffer);
....
bool Modify(unsigned char[] buf)
{
unsigned char temp[8];
//modify temp
memcpy((void *)buffer, (void *)header, sizeof(header));
Did you mean:
memcpy(buf, temp, sizeof temp);
Note that the casts are redundant. Redundant casts hide bugs that could
be detected at compile time.
}
The problem is that if I quickwatch buffer before the memcpy I can see
its content. It Shows the address and the first bytes of the content.
If I do the same after the memcpy I only can see the address, it
doesn't show the content. It also seems like the memcpy doesn't work
well, because if I quickwatch buffer[0] I can't see the first char in
header...
Am I doing something wrong?
Apart from the typos in the code (why didn't you use copy-and-paste?),
and the redundant casts, there's nothing wrong with what you've posted.
You might want to rule out the debugger (or your use of it) as the
problem by outputting the value of header and buffer at appropriate times.
Tom
.
- Follow-Ups:
- Re: Problem with VS and memcpy...
- From: John Carson
- Re: Problem with VS and memcpy...
- References:
- Problem with VS and memcpy...
- From: Paolo
- Re: Problem with VS and memcpy...
- From: Tom Widmer [VC++ MVP]
- Problem with VS and memcpy...
- Prev by Date: Re: Problem with VS and memcpy...
- Next by Date: Re: Problem with VS and memcpy...
- Previous by thread: Re: Problem with VS and memcpy...
- Next by thread: Re: Problem with VS and memcpy...
- Index(es):
Relevant Pages
|