Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
flatbuffers
Commits
b6ba322a
Commit
b6ba322a
authored
Aug 26, 2016
by
Sahil Jain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return error when full string cannot be parsed into int
parent
d05d1145
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
11 deletions
+16
-11
util.h
include/flatbuffers/util.h
+6
-6
idl_parser.cpp
src/idl_parser.cpp
+10
-5
No files found.
include/flatbuffers/util.h
View file @
b6ba322a
...
...
@@ -95,20 +95,20 @@ inline std::string IntToStringHex(int i, int xdigits) {
}
// Portable implementation of strtoll().
inline
int64_t
StringToInt
(
const
char
*
str
,
int
base
=
10
)
{
inline
int64_t
StringToInt
(
const
char
*
str
,
char
**
endptr
=
nullptr
,
int
base
=
10
)
{
#ifdef _MSC_VER
return
_strtoi64
(
str
,
null
ptr
,
base
);
return
_strtoi64
(
str
,
end
ptr
,
base
);
#else
return
strtoll
(
str
,
null
ptr
,
base
);
return
strtoll
(
str
,
end
ptr
,
base
);
#endif
}
// Portable implementation of strtoull().
inline
int64_t
StringToUInt
(
const
char
*
str
,
int
base
=
10
)
{
inline
int64_t
StringToUInt
(
const
char
*
str
,
char
**
endptr
=
nullptr
,
int
base
=
10
)
{
#ifdef _MSC_VER
return
_strtoui64
(
str
,
null
ptr
,
base
);
return
_strtoui64
(
str
,
end
ptr
,
base
);
#else
return
strtoull
(
str
,
null
ptr
,
base
);
return
strtoull
(
str
,
end
ptr
,
base
);
#endif
}
...
...
src/idl_parser.cpp
View file @
b6ba322a
...
...
@@ -219,7 +219,7 @@ CheckedError Parser::ParseHexNum(int nibbles, int64_t *val) {
return
Error
(
"escape code must be followed by "
+
NumToString
(
nibbles
)
+
" hex digits"
);
std
::
string
target
(
cursor_
,
cursor_
+
nibbles
);
*
val
=
StringToUInt
(
target
.
c_str
(),
16
);
*
val
=
StringToUInt
(
target
.
c_str
(),
nullptr
,
16
);
cursor_
+=
nibbles
;
return
NoError
();
}
...
...
@@ -447,7 +447,7 @@ CheckedError Parser::Next() {
cursor_
++
;
while
(
isxdigit
(
static_cast
<
unsigned
char
>
(
*
cursor_
)))
cursor_
++
;
attribute_
.
append
(
start
+
2
,
cursor_
);
attribute_
=
NumToString
(
StringToUInt
(
attribute_
.
c_str
(),
16
));
attribute_
=
NumToString
(
StringToUInt
(
attribute_
.
c_str
(),
nullptr
,
16
));
token_
=
kTokenIntegerConstant
;
return
NoError
();
}
...
...
@@ -1093,10 +1093,15 @@ CheckedError Parser::ParseSingleValue(Value &e) {
NEXT
();
}
else
{
// Numeric constant in string.
if
(
IsInteger
(
e
.
type
.
base_type
))
{
// TODO(wvo): do we want to check for garbage after the number?
e
.
constant
=
NumToString
(
StringToInt
(
attribute_
.
c_str
()));
char
*
end
;
e
.
constant
=
NumToString
(
StringToInt
(
attribute_
.
c_str
(),
&
end
));
if
(
*
end
)
return
Error
(
"invalid integer: "
+
attribute_
);
}
else
if
(
IsFloat
(
e
.
type
.
base_type
))
{
e
.
constant
=
NumToString
(
strtod
(
attribute_
.
c_str
(),
nullptr
));
char
*
end
;
e
.
constant
=
NumToString
(
strtod
(
attribute_
.
c_str
(),
&
end
));
if
(
*
end
)
return
Error
(
"invalid float: "
+
attribute_
);
}
else
{
assert
(
0
);
// Shouldn't happen, we covered all types.
e
.
constant
=
"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