Skip to content

Commit c8433ca

Browse files
committed
Address some feedback
1 parent 16d508d commit c8433ca

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Lib/test/test_exceptions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import errno
1111
from textwrap import dedent
1212

13+
from _testcapi import INT_MAX
1314
from test.support import (captured_stderr, check_impl_detail,
1415
cpython_only, gc_collect,
1516
no_tracing, script_helper,
@@ -322,19 +323,18 @@ def baz():
322323
@unittest.skipIf(ctypes.sizeof(ctypes.c_int) >= ctypes.sizeof(ctypes.c_ssize_t),
323324
"Downcasting to int is safe for col_offset")
324325
@support.requires_resource('cpu')
325-
@support.bigmemtest(2**(ctypes.sizeof(ctypes.c_int)*8-1)-1-len("pass"), memuse=1)
326+
@support.bigmemtest(INT_MAX, memuse=2, dry_run=False)
326327
def testMemoryErrorBigSource(self, size):
327-
if size < 2**(ctypes.sizeof(ctypes.c_int)*8-1)-1-len("pass"):
328+
padding_needed = INT_MAX-len("pass")
329+
if size < padding_needed:
328330
self.skipTest('Not enough memory for overflow to occur')
329331

330332
# Construct buffer to hold just enough characters so that the tokenizer offset overflows.
331333
# This makes sure that we don't overflow in the string creation itself
332-
distance_to_prev_divisible_by_8 = size & 7
333-
padding = ' ' * distance_to_prev_divisible_by_8
334-
padding += ' ' * ((size - distance_to_prev_divisible_by_8) // 8)
334+
src = f"if True:\n{' ' * padding_needed}pass"
335335

336336
with self.assertRaisesRegex(OverflowError, "Parser column offset overflow"):
337-
exec(f"if True:\n{padding}pass")
337+
compile(src, '<fragment>', 'exec')
338338

339339
@cpython_only
340340
def testSettingException(self):

Parser/lexer/lexer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ tok_nextc(struct tok_state *tok)
5959
int rc;
6060
for (;;) {
6161
if (tok->cur != tok->inp) {
62-
if (INT_MAX - tok->col_offset - 1 < 0) {
62+
if ((unsigned int) tok->col_offset >= (unsigned int) INT_MAX) {
6363
tok->done = E_COLUMNOVERFLOW;
6464
return EOF;
6565
}

0 commit comments

Comments
 (0)