Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
angle
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
angle
Commits
cc4ec64c
Commit
cc4ec64c
authored
Sep 23, 2013
by
Zhenyao Mo
Committed by
Jamie Madill
Sep 24, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the same mechanism to process int/float literals
This also fixes the float overflow errno leaking bug. BUG= R=alokp@chromium.org Review URL:
https://codereview.appspot.com/13368050
parent
ac44cd2b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
35 deletions
+7
-35
version.h
src/common/version.h
+1
-1
util.cpp
src/compiler/util.cpp
+6
-34
No files found.
src/common/version.h
View file @
cc4ec64c
#define MAJOR_VERSION 2
#define MAJOR_VERSION 2
#define MINOR_VERSION 0
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 201
4
#define BUILD_REVISION 201
5
#define STRINGIFY(x) #x
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
#define MACRO_STRINGIFY(x) STRINGIFY(x)
...
...
src/compiler/util.cpp
View file @
cc4ec64c
...
@@ -4,39 +4,15 @@
...
@@ -4,39 +4,15 @@
// found in the LICENSE file.
// found in the LICENSE file.
//
//
#include <math.h>
#include "compiler/util.h"
#include <stdlib.h>
#include <cerrno>
#include <limits>
#include <limits>
#include "util.h"
#include "compiler/preprocessor/numeric_lex.h"
#ifdef _MSC_VER
#include <locale.h>
#else
#include <sstream>
#endif
bool
atof_clamp
(
const
char
*
str
,
float
*
value
)
bool
atof_clamp
(
const
char
*
str
,
float
*
value
)
{
{
bool
success
=
true
;
bool
success
=
pp
::
numeric_lex_float
(
str
,
value
);
#ifdef _MSC_VER
_locale_t
l
=
_create_locale
(
LC_NUMERIC
,
"C"
);
double
dvalue
=
_atof_l
(
str
,
l
);
_free_locale
(
l
);
if
(
errno
==
ERANGE
||
dvalue
>
std
::
numeric_limits
<
float
>::
max
())
success
=
false
;
else
*
value
=
static_cast
<
float
>
(
dvalue
);
#else
std
::
istringstream
s
(
str
);
std
::
locale
l
(
"C"
);
s
.
imbue
(
l
);
s
>>
*
value
;
if
(
s
.
fail
())
success
=
false
;
#endif
if
(
!
success
)
if
(
!
success
)
*
value
=
std
::
numeric_limits
<
float
>::
max
();
*
value
=
std
::
numeric_limits
<
float
>::
max
();
return
success
;
return
success
;
...
@@ -44,13 +20,9 @@ bool atof_clamp(const char *str, float *value)
...
@@ -44,13 +20,9 @@ bool atof_clamp(const char *str, float *value)
bool
atoi_clamp
(
const
char
*
str
,
int
*
value
)
bool
atoi_clamp
(
const
char
*
str
,
int
*
value
)
{
{
long
int
lvalue
=
strtol
(
str
,
0
,
0
);
bool
success
=
pp
::
numeric_lex_int
(
str
,
value
);
if
(
errno
==
ERANGE
||
lvalue
>
std
::
numeric_limits
<
int
>::
max
())
if
(
!
success
)
{
*
value
=
std
::
numeric_limits
<
int
>::
max
();
*
value
=
std
::
numeric_limits
<
int
>::
max
();
return
false
;
return
success
;
}
*
value
=
static_cast
<
int
>
(
lvalue
);
return
true
;
}
}
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