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
407fb5d5
Commit
407fb5d5
authored
Mar 11, 2019
by
Vladimir Glavnyy
Committed by
Wouter van Oortmerssen
Mar 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Narrows template ascii routines to prevent a possible signed overflow in generic code. (#5232)
parent
73a648b6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
10 deletions
+10
-10
util.h
include/flatbuffers/util.h
+8
-8
idl_parser.cpp
src/idl_parser.cpp
+2
-2
No files found.
include/flatbuffers/util.h
View file @
407fb5d5
...
...
@@ -35,19 +35,19 @@ namespace flatbuffers {
// @locale-independent functions for ASCII characters set.
//
Check that integer scalar is in closed range: (a <= x <= b)
//
Fast checking that character lies in closed range: [a <= x <= b]
// using one compare (conditional branch) operator.
template
<
typename
T
>
inline
bool
check_in_range
(
T
x
,
T
a
,
T
b
)
{
inline
bool
check_ascii_range
(
char
x
,
char
a
,
char
b
)
{
FLATBUFFERS_ASSERT
(
a
<=
b
);
// (Hacker's Delight): `a <= x <= b` <=> `(x-a) <={u} (b-a)`.
FLATBUFFERS_ASSERT
(
a
<=
b
);
// static_assert only if 'a' & 'b' templated
typedef
typename
flatbuffers
::
make_unsigned
<
T
>::
type
U
;
return
(
static_cast
<
U
>
(
x
-
a
)
<=
static_cast
<
U
>
(
b
-
a
));
// The x, a, b will be promoted to int and subtracted without overflow.
return
static_cast
<
unsigned
int
>
(
x
-
a
)
<=
static_cast
<
unsigned
int
>
(
b
-
a
);
}
// Case-insensitive isalpha
inline
bool
is_alpha
(
char
c
)
{
// ASCII only: alpha to upper case => reset bit 0x20 (~0x20 = 0xDF).
return
check_
in
_range
(
c
&
0xDF
,
'a'
&
0xDF
,
'z'
&
0xDF
);
return
check_
ascii
_range
(
c
&
0xDF
,
'a'
&
0xDF
,
'z'
&
0xDF
);
}
// Check (case-insensitive) that `c` is equal to alpha.
...
...
@@ -62,11 +62,11 @@ inline bool is_alpha_char(char c, char alpha) {
// functions that are not affected by the currently installed C locale. although
// some implementations (e.g. Microsoft in 1252 codepage) may classify
// additional single-byte characters as digits.
inline
bool
is_digit
(
char
c
)
{
return
check_
in
_range
(
c
,
'0'
,
'9'
);
}
inline
bool
is_digit
(
char
c
)
{
return
check_
ascii
_range
(
c
,
'0'
,
'9'
);
}
inline
bool
is_xdigit
(
char
c
)
{
// Replace by look-up table.
return
is_digit
(
c
)
||
check_
in
_range
(
c
&
0xDF
,
'a'
&
0xDF
,
'f'
&
0xDF
);
return
is_digit
(
c
)
||
check_
ascii
_range
(
c
&
0xDF
,
'a'
&
0xDF
,
'f'
&
0xDF
);
}
// Case-insensitive isalnum
...
...
src/idl_parser.cpp
View file @
407fb5d5
...
...
@@ -374,7 +374,7 @@ CheckedError Parser::Next() {
"illegal Unicode sequence (unpaired high surrogate)"
);
}
// reset if non-printable
attr_is_trivial_ascii_string_
&=
check_
in
_range
(
*
cursor_
,
' '
,
'~'
);
attr_is_trivial_ascii_string_
&=
check_
ascii
_range
(
*
cursor_
,
' '
,
'~'
);
attribute_
+=
*
cursor_
++
;
}
...
...
@@ -476,7 +476,7 @@ CheckedError Parser::Next() {
}
std
::
string
ch
;
ch
=
c
;
if
(
false
==
check_
in
_range
(
c
,
' '
,
'~'
))
ch
=
"code: "
+
NumToString
(
c
);
if
(
false
==
check_
ascii
_range
(
c
,
' '
,
'~'
))
ch
=
"code: "
+
NumToString
(
c
);
return
Error
(
"illegal character: "
+
ch
);
}
}
...
...
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