This repository has been archived by the owner. It is now read-only.

Fix ADDR_TO_LOC for i386 (32 bit) #62

Open
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
1 participant
@olebole
Contributor

olebole commented May 16, 2017

The address LOC needs to be not negative. The right shift in the original code however may be (implementation dependent) shift in a 1, resulting in a negative LOC:

ISO/IEC 9899/1999, §6.5.8:

  1. The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed type and a nonnegative value, the value of the result is the integral part of the quotient of E1 / 2^E2. If E1 has a signed type and a negative value, the resulting value is implementation-defined.

We explicitly cast it into an unsigned before rightshifting. This will shift in a zero.

This fixes #61.

We can also remove an ugly "workaround" for this problem in the cl startup shell script.

@olebole olebole changed the title from Reset the MSB in the result of ADDR_TO_LOC to Typecast address to an unsigned int before rightshifting in ADDR_TO_LOC May 21, 2017

@olebole olebole changed the title from Typecast address to an unsigned int before rightshifting in ADDR_TO_LOC to Fix ADDR_TO_LOC (and LOC_TO_ADDR) Jul 30, 2017

Reset the MSB in the result of ADDR_TO_LOC
This is needed since LOC is later checked to be not negative, but the
result of right-shifting the original address may result in a negative value.

Since we left-shift to get back the address, this bit is lost anyway,
as long as `XCHAR` is `short` (hardcoded in many places).

@olebole olebole changed the title from Fix ADDR_TO_LOC (and LOC_TO_ADDR) to Fix ADDR_TO_LOC for i386 (32 bit) Jul 30, 2017

Remove `ulimit -s unlimited` from cl startup
The `ADDR_TO_LOC` fix also fixes the dubious "problem how pointer
adresses interact with the stack", so the workaround with
`ulimit -s unlimited` can be removed here.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.