Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
41525e31
Commit
41525e31
authored
Apr 03, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23466: Raised OverflowError if %c argument is out of range.
parent
45ec3288
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
9 deletions
+14
-9
Lib/test/test_format.py
Lib/test/test_format.py
+6
-6
Objects/bytesobject.c
Objects/bytesobject.c
+8
-3
No files found.
Lib/test/test_format.py
View file @
41525e31
...
...
@@ -358,12 +358,12 @@ class FormatTest(unittest.TestCase):
"not all arguments converted during bytes formatting"
)
test_exc
(
b'no format'
,
bytearray
(
b'1'
),
TypeError
,
"not all arguments converted during bytes formatting"
)
test_exc
(
b"%c"
,
-
1
,
Type
Error
,
"%c
requires an integer in range(256) or a single byte
"
)
test_exc
(
b"%c"
,
256
,
Type
Error
,
"%c
requires an integer in range(256) or a single byte
"
)
test_exc
(
b"%c"
,
2
**
128
,
Type
Error
,
"%c
requires an integer in range(256) or a single byte
"
)
test_exc
(
b"%c"
,
-
1
,
Overflow
Error
,
"%c
arg not in range(256)
"
)
test_exc
(
b"%c"
,
256
,
Overflow
Error
,
"%c
arg not in range(256)
"
)
test_exc
(
b"%c"
,
2
**
128
,
Overflow
Error
,
"%c
arg not in range(256)
"
)
test_exc
(
b"%c"
,
b"Za"
,
TypeError
,
"%c requires an integer in range(256) or a single byte"
)
test_exc
(
b"%c"
,
"Y"
,
TypeError
,
...
...
Objects/bytesobject.c
View file @
41525e31
...
...
@@ -496,10 +496,15 @@ byte_converter(PyObject *arg, char *p)
ival
=
PyLong_AsLongAndOverflow
(
iobj
,
&
overflow
);
Py_DECREF
(
iobj
);
}
if
(
!
overflow
&&
0
<=
ival
&&
ival
<=
255
)
{
*
p
=
(
char
)
ival
;
return
1
;
if
(
!
overflow
&&
ival
==
-
1
&&
PyErr_Occurred
())
goto
onError
;
if
(
overflow
||
!
(
0
<=
ival
&&
ival
<=
255
))
{
PyErr_SetString
(
PyExc_OverflowError
,
"%c arg not in range(256)"
);
return
0
;
}
*
p
=
(
char
)
ival
;
return
1
;
}
onError:
PyErr_SetString
(
PyExc_TypeError
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment