S
Sushil
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
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