summaryrefslogtreecommitdiff
path: root/rts/posix
diff options
context:
space:
mode:
authorAlec Theriault <alec.theriault@gmail.com>2019-05-13 15:31:56 -0700
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-05-22 16:48:45 -0400
commitecc9366a0e0db107c286935130837b2222e2dd82 (patch)
treebd0eceaf7b88104e2ca105f089b85b8dd95fe19c /rts/posix
parent78c3f3305e173c7667ffb47b97ff0ecacc279fe5 (diff)
downloadhaskell-ecc9366a0e0db107c286935130837b2222e2dd82.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).
Diffstat (limited to 'rts/posix')
-rw-r--r--rts/posix/OSMem.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c
index 4e5c5c170f..cf4b705d74 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