Skip to content

Commit 016cdff

Browse files
youknowdotcodex
andauthored
Use native signed width for warning stack levels (#9539)
Avoid decrementing nonpositive stack levels so the signed minimum cannot overflow during frame selection. Assisted-by: OpenAI Codex:model version not exposed Co-authored-by: Codex <[email protected]>
1 parent 8a72d81 commit 016cdff

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

‎crates/vm/src/stdlib/_warnings.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ mod _warnings {
8787
#[pyarg(any, optional)]
8888
category: OptionalArg<PyObjectRef>,
8989
#[pyarg(any, default = 1)]
90-
stacklevel: i32,
90+
stacklevel: isize,
9191
#[pyarg(any, optional)]
9292
source: OptionalArg<PyObjectRef>,
9393
#[pyarg(named, optional)]
@@ -127,7 +127,7 @@ mod _warnings {
127127

128128
#[pyfunction]
129129
fn warn(args: WarnArgs, vm: &VirtualMachine) -> PyResult<()> {
130-
let level = args.stacklevel as isize;
130+
let level = args.stacklevel;
131131

132132
let category = get_category(&args.message, args.category.into_option(), vm)?;
133133

‎crates/vm/src/warn.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -744,20 +744,16 @@ fn setup_context(
744744
// Stack level comparisons to Python code is off by one as there is no
745745
// warnings-related stack level to avoid.
746746
if stack_level <= 0 || f.as_ref().is_some_and(|frame| frame.is_internal_frame()) {
747-
while {
747+
while stack_level > 1 {
748748
stack_level -= 1;
749-
stack_level > 0
750-
} {
751749
match f {
752750
Some(tmp) => f = tmp.f_back(vm),
753751
None => break,
754752
}
755753
}
756754
} else {
757-
while {
755+
while stack_level > 1 {
758756
stack_level -= 1;
759-
stack_level > 0
760-
} {
761757
match f {
762758
Some(tmp) => f = next_external_frame_with_skip(&tmp, skip_file_prefixes, vm),
763759
None => break,

0 commit comments

Comments
 (0)