Skip to content

Commit d0cdae2

Browse files
committed
---
yaml --- r: 188313 b: refs/heads/tmp c: 243c516 h: refs/heads/master i: 188311: f31f80b v: v3
1 parent 1918515 commit d0cdae2

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 522d09dfecbeca1595f25ac58c6d0178bbd21d7d
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: 185c074798ce87429118868c292d2c2c7dc46cfc
37+
refs/heads/tmp: 243c5164ea32b38c4ac44fdd5e0ceb2da45c283f
3838
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/tmp/src/libstd/rt/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use marker::Send;
2727
use ops::FnOnce;
2828
use sys;
2929
use thunk::Thunk;
30+
use usize;
3031

3132
// Reexport some of our utilities which are expected by other crates.
3233
pub use self::util::{default_sched_threads, min_stack, running_on_valgrind};
@@ -78,7 +79,20 @@ fn lang_start(main: *const u8, argc: int, argv: *const *const u8) -> int {
7879
// FIXME #11359 we just assume that this thread has a stack of a
7980
// certain size, and estimate that there's at most 20KB of stack
8081
// frames above our current position.
81-
let my_stack_bottom = my_stack_top + 20000 - OS_DEFAULT_STACK_ESTIMATE;
82+
const TWENTY_KB: uint = 20000;
83+
84+
// saturating-add to sidestep overflow
85+
let top_plus_spill = if usize::MAX - TWENTY_KB < my_stack_top {
86+
usize::MAX
87+
} else {
88+
my_stack_top + TWENTY_KB
89+
};
90+
// saturating-sub to sidestep underflow
91+
let my_stack_bottom = if top_plus_spill < OS_DEFAULT_STACK_ESTIMATE {
92+
0
93+
} else {
94+
top_plus_spill - OS_DEFAULT_STACK_ESTIMATE
95+
};
8296

8397
let failed = unsafe {
8498
// First, make sure we don't trigger any __morestack overflow checks,

0 commit comments

Comments
 (0)