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
12a5a479
Commit
12a5a479
authored
Oct 12, 2006
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug #1545497: when given an explicit base, int() did ignore NULs
embedded in the string to convert.
parent
fc6fa407
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
2 deletions
+27
-2
Lib/test/test_builtin.py
Lib/test/test_builtin.py
+5
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/intobject.c
Objects/intobject.c
+19
-2
No files found.
Lib/test/test_builtin.py
View file @
12a5a479
...
...
@@ -729,6 +729,11 @@ class BuiltinTest(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
int
,
'123
\
0
'
)
self
.
assertRaises
(
ValueError
,
int
,
'53'
,
40
)
# SF bug 1545497: embedded NULs were not detected with
# explicit base
self
.
assertRaises
(
ValueError
,
int
,
'123
\
0
'
,
10
)
self
.
assertRaises
(
ValueError
,
int
,
'123
\
x00
245'
,
20
)
x
=
int
(
'1'
*
600
)
self
.
assert_
(
isinstance
(
x
,
long
))
...
...
Misc/NEWS
View file @
12a5a479
...
...
@@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 1?
Core and builtins
-----------------
- Bug #1545497: when given an explicit base, int() did ignore NULs
embedded in the string to convert.
- Bug #1569998: break inside a try statement (outside a loop) is now
recognized and rejected.
...
...
Objects/intobject.c
View file @
12a5a479
...
...
@@ -987,8 +987,25 @@ int_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
PyInt_FromLong
(
0L
);
if
(
base
==
-
909
)
return
PyNumber_Int
(
x
);
if
(
PyString_Check
(
x
))
return
PyInt_FromString
(
PyString_AS_STRING
(
x
),
NULL
,
base
);
if
(
PyString_Check
(
x
))
{
/* Since PyInt_FromString doesn't have a length parameter,
* check here for possible NULs in the string. */
char
*
string
=
PyString_AS_STRING
(
x
);
if
(
strlen
(
string
)
!=
PyString_Size
(
x
))
{
/* create a repr() of the input string,
* just like PyInt_FromString does */
PyObject
*
srepr
;
srepr
=
PyObject_Repr
(
x
);
if
(
srepr
==
NULL
)
return
NULL
;
PyErr_Format
(
PyExc_ValueError
,
"invalid literal for int() with base %d: %s"
,
base
,
PyString_AS_STRING
(
srepr
));
Py_DECREF
(
srepr
);
return
NULL
;
}
return
PyInt_FromString
(
string
,
NULL
,
base
);
}
#ifdef Py_USING_UNICODE
if
(
PyUnicode_Check
(
x
))
return
PyInt_FromUnicode
(
PyUnicode_AS_UNICODE
(
x
),
...
...
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