Re: pointer one past malloc.ed memory
From: Joe Wright (joewwright_at_comcast.net)
Date: 07/11/04
- Next message: Amit Bhatia: "Re: Floating point arithmetic."
- Previous message: Curley Q.: "Re: rounding function?"
- In reply to: Sushil: "pointer one past malloc.ed memory"
- Next in thread: Sushil: "Re: pointer one past malloc.ed memory"
- Reply: Sushil: "Re: pointer one past malloc.ed memory"
- Reply: Eric Sosman: "Re: pointer one past malloc.ed memory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 11 Jul 2004 10:50:06 -0400
Sushil wrote:
> Hi Gurus
>
> I've tried to come up with a small logical example of my problem.
> The problem is platform specific (MIPS) which I understand should not
> be discussed here.
>
> So here goes my example:
>
> Code is doing malloc of variable sizes.
> The last byte of malloc.ed memory is written a magic.
> Since the size if variable (and iit ncludes magic), the code adds size
> and subtracts sizeof magic to access the magic.
> Now this is where the problem comes.
> The calculation of address generates an overflow exception.
>
> Let me give an example (it's a corner case I ran into)
> 0x8000 0000 is end of the malloc.ed memory and magic is 8 bytes
> so it is a lw $v0, -8($v0)
>
> 0x8000 0000 + -8 is generating an overflow exception for address.
> The address 0x7fff fff8, is perfectly valid to dereference but
> *computation* of the address is overflowing.
>
> Sorry i had to give some platform specific details.
> But I am hoping it will clarify my question.
>
> Now my question to you about C language is:
> Can we have the address 1 byte beyond the malloc.ed area (no it is not
> dereferenced) and then a negative offset into it to legitimately
> dereference the memory malloc.ed by malloc()?
> What does the standard say here?
> Or is it just another case of overflow and we can not blame MIPS
> load-store unit for overflown address generation (thats what I think).
>
> I've solved the problem by first subtracting 8 then adding size . i.e.
> instead of load from -8(ptr) I forced the code to do ptr to point to 8
> bytes earlier and then load from 0(ptr). But I want to know what the
> standard says about the address of malloc.ed memory.
>
> Thanks
> - Ramachandran
We generally don't know MIPS assembler and as a C programmer, you
shouldn't care. If you care to post some C code which exhibits the
problem, several people here might be more able to help you.
Note that 0x80000000 is -2147483648 or INT_MIN on 32-bit systems.
--
Joe Wright mailto:joewwright@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
- Next message: Amit Bhatia: "Re: Floating point arithmetic."
- Previous message: Curley Q.: "Re: rounding function?"
- In reply to: Sushil: "pointer one past malloc.ed memory"
- Next in thread: Sushil: "Re: pointer one past malloc.ed memory"
- Reply: Sushil: "Re: pointer one past malloc.ed memory"
- Reply: Eric Sosman: "Re: pointer one past malloc.ed memory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|