Solved

Assertion on memcpy

Posted on 2013-01-27
2
786 Views
Last Modified: 2013-02-06
Greetings,
I'm using Visual studio 2005 to run some of company's C++ code on an emulator. This is a build with debug info enabled.
At a certain point I get a crash on a memcpy. My src pointer is a pointer to an offset on a memory mapped file. This address is calculated by our memory mapping code. Athe moment of the crash src = 0x3084f87a.
 dst is a buffer big enough to hold the data we want to copy (6022 bytes).

The output gives me the following messages:
I know it seems like a open an shut case, but I fail to understand what's so special about the address.

First-chance exception at 0x023211ea in prog.exe: 0xC0000005: Access violation reading location 0x30850000.
Unhandled exception at 0x023211ea in prog.exe: 0xC0000005: Access violation reading location 0x30850000.

Below is a snapshot of memcpy.asm. Visual studio pointed to the line starting with 'rep'.

Dword_align:
        test    edi,11b         ;U - destination dword aligned?
        jnz     short CopyLeadUp ;V - if we are not dword aligned already, align

        shr     ecx,2           ;U - shift down to dword count
        and     edx,11b         ;V - trailing byte count

        cmp     ecx,8           ;U - test if small enough for unwind copy
        jb      short CopyUnwindUp ;V - if so, then jump

       rep     movsd           ;N - move all of our dwords

        jmp     dword ptr TrailUpVec[edx*4] ;N - process trailing bytes

Open in new window


If anyone can help me get some clarity into this I would appreciate it.
r
0
Comment
Question by:rjorge
2 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 38824369
Hard to tell what's going on without more info (or code). Can you verify the validity of the source pointer using 'IsBadReadPtr()' (http://msdn.microsoft.com/en-us/library/aa366713(VS.85).aspx) prior to calling 'memcpy()'? Maybe something went wrong with the offset calculation...
0
 
LVL 22

Accepted Solution

by:
ambience earned 335 total points
ID: 38825053
Could very well be that the mem-mapper unmapped a view that you still had a reference to? More than likely, in crashes like that, the cause of the issue is some other part of code, especially in multi-threaded applications.

I would suggest that you create execution logs especially for what goes inside the mem-mapper. If logging isn't already infused into the codebase you can still use Visual studio breakpoints to create a log. Having a log would layout a pattern for when the error doesn't happen and when it does.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question