Find Jobs
Hire Freelancers

C++ Memory management Crash Issue

$30-100 USD

Cancelled
Posted about 17 years ago

$30-100 USD

Paid on delivery
**I have a crash happening and I want step-by-step explanation as to why that is. e.g: **a) the list grows by ... ... b) the list exceeds at... ... c) crashes because... ... ## Deliverables 1) Step by step explanation of the why the crash is happening. e.g: a) the list grows by ... ... b) the list exceeds at... ... c) crashes because... ... 2) Provide the right fix. Modify the ArrayInsert function with the complete fix. 3) Will only accept the answer if it fixes the crash in my product when I copy over the modified ArrayInsert function. **Here is the code that is inserting elements into an array.** void*MyMem::ArrayInsert (void *ptr, void *element, USHORT elementSize, USHORT insertPoint, USHORT elementCount, USHORT allocCount) { unsigned int moveSize; unsigned int allocSize; ULONG elementsAlloced; char *src; char *dst; if (ptr == NULL) { allocSize = (unsigned int)elementSize * (unsigned int) allocCount; ptr = Alloc(allocSize); if (ptr == NULL) { return (NULL); } elementsAlloced = allocCount; } else { USHORT size = (USHORT) Util::MemGetSize (ptr); //returns unsigned int size memory elementsAlloced = (USHORT) (size / elementSize); } // if if (elementCount >= elementsAlloced) { elementsAlloced = elementsAlloced + allocCount; allocSize = (unsigned int)elementSize * (unsigned int) elementsAlloced; ptr = ReAlloc(ptr, allocSize); if (ptr == NULL) { return (NULL); } // if } // if src = (char *)ptr + ((SLONG)insertPoint * (SLONG)elementSize); dst = src + elementSize; moveSize = (unsigned int)elementSize * (elementCount-insertPoint); if (moveSize > 0) { memmove(dst, src, moveSize); } // if dst = src; memcpy(dst, element, elementSize); return (ptr); } // ArrayInsert **Here is the how this function is called:** ArrayInsert(void * ptr=0x00000000, void * element=0x0013bb10, unsigned short elementSize=16, unsigned short insertPoint=0, unsigned short elementCount=0, unsigned short allocCount=20) **However, when accessing this array, it crashes at index: 2041. Need explanation about the crash and fix for it. That's it.** ## Platform WIN XP. microsoft visual studio 2005. C++.
Project ID: 2952561

About the project

2 proposals
Remote project
Active 17 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
2 freelancers are bidding on average $7 USD for this job
User Avatar
See private message.
$4.25 USD in 1 day
5.0 (3 reviews)
5.5
5.5
User Avatar
See private message.
$10.20 USD in 1 day
5.0 (43 reviews)
4.4
4.4

About the client

Flag of UNITED STATES
United States
0.0
0
Member since May 3, 2007

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.