Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Assertion on memcpy

Posted on 2013-01-27
2
Medium Priority
?
841 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1340 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

722 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