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
1f4fc097
Commit
1f4fc097
authored
Sep 13, 2009
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix potential signed-overflow bug in _PyLong_Format; also fix
a couple of whitespace issues.
parent
3d85454b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
9 deletions
+11
-9
Objects/longobject.c
Objects/longobject.c
+11
-9
No files found.
Objects/longobject.c
View file @
1f4fc097
...
@@ -1371,7 +1371,7 @@ _PyLong_Format(PyObject *aa, int base, int addL, int newstyle)
...
@@ -1371,7 +1371,7 @@ _PyLong_Format(PyObject *aa, int base, int addL, int newstyle)
{
{
register
PyLongObject
*
a
=
(
PyLongObject
*
)
aa
;
register
PyLongObject
*
a
=
(
PyLongObject
*
)
aa
;
PyStringObject
*
str
;
PyStringObject
*
str
;
Py_ssize_t
i
,
j
,
sz
;
Py_ssize_t
i
,
sz
;
Py_ssize_t
size_a
;
Py_ssize_t
size_a
;
char
*
p
;
char
*
p
;
int
bits
;
int
bits
;
...
@@ -1392,13 +1392,14 @@ _PyLong_Format(PyObject *aa, int base, int addL, int newstyle)
...
@@ -1392,13 +1392,14 @@ _PyLong_Format(PyObject *aa, int base, int addL, int newstyle)
i
>>=
1
;
i
>>=
1
;
}
}
i
=
5
+
(
addL
?
1
:
0
);
i
=
5
+
(
addL
?
1
:
0
);
j
=
size_a
*
PyLong_SHIFT
+
bits
-
1
;
/* ensure we don't get signed overflow in sz calculation */
sz
=
i
+
j
/
bits
;
if
(
size_a
>
(
PY_SSIZE_T_MAX
-
i
)
/
PyLong_SHIFT
)
{
if
(
j
/
PyLong_SHIFT
<
size_a
||
sz
<
i
)
{
PyErr_SetString
(
PyExc_OverflowError
,
PyErr_SetString
(
PyExc_OverflowError
,
"long is too large to format"
);
"long is too large to format"
);
return
NULL
;
return
NULL
;
}
}
sz
=
i
+
1
+
(
size_a
*
PyLong_SHIFT
-
1
)
/
bits
;
assert
(
sz
>=
0
);
str
=
(
PyStringObject
*
)
PyString_FromStringAndSize
((
char
*
)
0
,
sz
);
str
=
(
PyStringObject
*
)
PyString_FromStringAndSize
((
char
*
)
0
,
sz
);
if
(
str
==
NULL
)
if
(
str
==
NULL
)
return
NULL
;
return
NULL
;
...
@@ -1448,7 +1449,8 @@ _PyLong_Format(PyObject *aa, int base, int addL, int newstyle)
...
@@ -1448,7 +1449,8 @@ _PyLong_Format(PyObject *aa, int base, int addL, int newstyle)
int
power
=
1
;
int
power
=
1
;
for
(;;)
{
for
(;;)
{
twodigits
newpow
=
powbase
*
(
twodigits
)
base
;
twodigits
newpow
=
powbase
*
(
twodigits
)
base
;
if
(
newpow
>>
PyLong_SHIFT
)
/* doesn't fit in a digit */
if
(
newpow
>>
PyLong_SHIFT
)
/* doesn't fit in a digit */
break
;
break
;
powbase
=
(
digit
)
newpow
;
powbase
=
(
digit
)
newpow
;
++
power
;
++
power
;
...
...
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