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
a406c0a6
Commit
a406c0a6
authored
Sep 13, 2016
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve type-safe of and prevent double-frees in get_locale_info (#28119)
parent
e81a68a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
17 deletions
+9
-17
Python/formatter_unicode.c
Python/formatter_unicode.c
+9
-17
No files found.
Python/formatter_unicode.c
View file @
a406c0a6
...
...
@@ -347,9 +347,11 @@ fill_padding(_PyUnicodeWriter *writer,
/************************************************************************/
/* Locale type codes. */
#define LT_CURRENT_LOCALE 0
#define LT_DEFAULT_LOCALE 1
#define LT_NO_LOCALE 2
enum
LocaleType
{
LT_CURRENT_LOCALE
,
LT_DEFAULT_LOCALE
,
LT_NO_LOCALE
};
/* Locale info needed for formatting integers and the part of floats
before and including the decimal. Note that locales only support
...
...
@@ -663,7 +665,7 @@ static char no_grouping[1] = {CHAR_MAX};
LT_CURRENT_LOCALE, a hard-coded locale if LT_DEFAULT_LOCALE, or
none if LT_NO_LOCALE. */
static
int
get_locale_info
(
int
type
,
LocaleInfo
*
locale_info
)
get_locale_info
(
enum
LocaleType
type
,
LocaleInfo
*
locale_info
)
{
switch
(
type
)
{
case
LT_CURRENT_LOCALE
:
{
...
...
@@ -676,21 +678,16 @@ get_locale_info(int type, LocaleInfo *locale_info)
locale_info
->
thousands_sep
=
PyUnicode_DecodeLocale
(
locale_data
->
thousands_sep
,
NULL
);
if
(
locale_info
->
thousands_sep
==
NULL
)
{
Py_DECREF
(
locale_info
->
decimal_point
);
if
(
locale_info
->
thousands_sep
==
NULL
)
return
-
1
;
}
locale_info
->
grouping
=
locale_data
->
grouping
;
break
;
}
case
LT_DEFAULT_LOCALE
:
locale_info
->
decimal_point
=
PyUnicode_FromOrdinal
(
'.'
);
locale_info
->
thousands_sep
=
PyUnicode_FromOrdinal
(
','
);
if
(
!
locale_info
->
decimal_point
||
!
locale_info
->
thousands_sep
)
{
Py_XDECREF
(
locale_info
->
decimal_point
);
Py_XDECREF
(
locale_info
->
thousands_sep
);
if
(
!
locale_info
->
decimal_point
||
!
locale_info
->
thousands_sep
)
return
-
1
;
}
locale_info
->
grouping
=
"
\3
"
;
/* Group every 3 characters. The
(implicit) trailing 0 means repeat
infinitely. */
...
...
@@ -698,15 +695,10 @@ get_locale_info(int type, LocaleInfo *locale_info)
case
LT_NO_LOCALE
:
locale_info
->
decimal_point
=
PyUnicode_FromOrdinal
(
'.'
);
locale_info
->
thousands_sep
=
PyUnicode_New
(
0
,
0
);
if
(
!
locale_info
->
decimal_point
||
!
locale_info
->
thousands_sep
)
{
Py_XDECREF
(
locale_info
->
decimal_point
);
Py_XDECREF
(
locale_info
->
thousands_sep
);
if
(
!
locale_info
->
decimal_point
||
!
locale_info
->
thousands_sep
)
return
-
1
;
}
locale_info
->
grouping
=
no_grouping
;
break
;
default:
assert
(
0
);
}
return
0
;
}
...
...
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