Solved

Assertion on memcpy

Posted on 2013-01-27
2
762 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

813 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now