diff options
author | Alec Theriault <alec.theriault@gmail.com> | 2019-05-13 15:31:56 -0700 |
---|---|---|
committer | Ben Gamari <ben@well-typed.com> | 2019-06-03 23:41:59 -0400 |
commit | 5d68a56b2fe016f64e93a5ae68e4df96368669d2 (patch) | |
tree | 8562de4ad7100205f600d26f991afb57d0ee0b26 | |
parent | 605869c7b776ce6071a31ff447998b081e0354ed (diff) | |
download | haskell-5d68a56b2fe016f64e93a5ae68e4df96368669d2.tar.gz |
RTS: Fix restrictive cast
Commit e75a9afd2989e0460f9b49fa07c1667299d93ee9 added an `unsigned` cast
to account for OSes that have signed `rlim_t` signed. Unfortunately,
the `unsigned` cast has the unintended effect of narrowing `rlim_t` to
only 4 bytes. This leads to some spurious out of memory crashes
(in particular: Haddock crashes with OOM whenn building docs of
`ghc`-the-library).
In this case, `W_` is a better type to cast to: we know it will be
unsigned too and it has the same type as `*len` (so we don't suffer from
accidental narrowing).
-rw-r--r-- | rts/posix/OSMem.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c index bab0b64dae..7a8cd9ab87 100644 --- a/rts/posix/OSMem.c +++ b/rts/posix/OSMem.c @@ -550,8 +550,8 @@ void *osReserveHeapMemory(void *startAddressPtr, W_ *len) * explicitly cast to avoid sign compare error */ if (!getrlimit(RLIMIT_AS, &limit) && limit.rlim_cur > 0 - && *len > (unsigned) limit.rlim_cur) { - *len = (unsigned) limit.rlim_cur; + && *len > (W_) limit.rlim_cur) { + *len = (W_) limit.rlim_cur; } #endif |