Solved

Assertion on memcpy

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

Independent Software Vendors: 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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
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.

734 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