Solved

Assertion on memcpy

Posted on 2013-01-27
2
732 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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

762 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

8 Experts available now in Live!

Get 1:1 Help Now