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
c41a0453
Commit
c41a0453
authored
May 23, 2016
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/google/flatbuffers
parents
1a161a83
2de55805
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
2 deletions
+36
-2
CMakeLists.txt
CMakeLists.txt
+3
-0
idl_parser.cpp
src/idl_parser.cpp
+5
-2
test.cpp
tests/test.cpp
+28
-0
No files found.
CMakeLists.txt
View file @
c41a0453
...
@@ -136,6 +136,9 @@ endif()
...
@@ -136,6 +136,9 @@ endif()
if
(
FLATBUFFERS_BUILD_FLATC
)
if
(
FLATBUFFERS_BUILD_FLATC
)
add_executable
(
flatc
${
FlatBuffers_Compiler_SRCS
}
)
add_executable
(
flatc
${
FlatBuffers_Compiler_SRCS
}
)
if
(
NOT FLATBUFFERS_FLATC_EXECUTABLE
)
set
(
FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>
)
endif
()
endif
()
endif
()
if
(
FLATBUFFERS_BUILD_FLATHASH
)
if
(
FLATBUFFERS_BUILD_FLATHASH
)
...
...
src/idl_parser.cpp
View file @
c41a0453
...
@@ -69,13 +69,16 @@ inline CheckedError NoError() { return CheckedError(false); }
...
@@ -69,13 +69,16 @@ inline CheckedError NoError() { return CheckedError(false); }
// Ensure that integer values we parse fit inside the declared integer type.
// Ensure that integer values we parse fit inside the declared integer type.
CheckedError
Parser
::
CheckBitsFit
(
int64_t
val
,
size_t
bits
)
{
CheckedError
Parser
::
CheckBitsFit
(
int64_t
val
,
size_t
bits
)
{
// Left-shifting a 64-bit value by 64 bits or more is undefined
// behavior (C99 6.5.7), so check *before* we shift.
if
(
bits
<
64
)
{
// Bits we allow to be used.
// Bits we allow to be used.
auto
mask
=
static_cast
<
int64_t
>
((
1ull
<<
bits
)
-
1
);
auto
mask
=
static_cast
<
int64_t
>
((
1ull
<<
bits
)
-
1
);
if
(
bits
<
64
&&
if
((
val
&
~
mask
)
!=
0
&&
// Positive or unsigned.
(
val
&
~
mask
)
!=
0
&&
// Positive or unsigned.
(
val
|
mask
)
!=
-
1
)
// Negative.
(
val
|
mask
)
!=
-
1
)
// Negative.
return
Error
(
"constant does not fit in a "
+
NumToString
(
bits
)
+
return
Error
(
"constant does not fit in a "
+
NumToString
(
bits
)
+
"-bit field"
);
"-bit field"
);
}
return
NoError
();
return
NoError
();
}
}
...
...
tests/test.cpp
View file @
c41a0453
...
@@ -819,6 +819,33 @@ void EnumStringsTest() {
...
@@ -819,6 +819,33 @@ void EnumStringsTest() {
"{ F:[
\"
E.C
\"
,
\"
E.A E.B E.C
\"
] }"
),
true
);
"{ F:[
\"
E.C
\"
,
\"
E.A E.B E.C
\"
] }"
),
true
);
}
}
void
IntegerOutOfRangeTest
()
{
TestError
(
"table T { F:byte; } root_type T; { F:256 }"
,
"constant does not fit"
);
TestError
(
"table T { F:byte; } root_type T; { F:-257 }"
,
"constant does not fit"
);
TestError
(
"table T { F:ubyte; } root_type T; { F:256 }"
,
"constant does not fit"
);
TestError
(
"table T { F:ubyte; } root_type T; { F:-257 }"
,
"constant does not fit"
);
TestError
(
"table T { F:short; } root_type T; { F:65536 }"
,
"constant does not fit"
);
TestError
(
"table T { F:short; } root_type T; { F:-65537 }"
,
"constant does not fit"
);
TestError
(
"table T { F:ushort; } root_type T; { F:65536 }"
,
"constant does not fit"
);
TestError
(
"table T { F:ushort; } root_type T; { F:-65537 }"
,
"constant does not fit"
);
TestError
(
"table T { F:int; } root_type T; { F:4294967296 }"
,
"constant does not fit"
);
TestError
(
"table T { F:int; } root_type T; { F:-4294967297 }"
,
"constant does not fit"
);
TestError
(
"table T { F:uint; } root_type T; { F:4294967296 }"
,
"constant does not fit"
);
TestError
(
"table T { F:uint; } root_type T; { F:-4294967297 }"
,
"constant does not fit"
);
}
void
UnicodeTest
()
{
void
UnicodeTest
()
{
flatbuffers
::
Parser
parser
;
flatbuffers
::
Parser
parser
;
TEST_EQ
(
parser
.
Parse
(
"table T { F:string; }"
TEST_EQ
(
parser
.
Parse
(
"table T { F:string; }"
...
@@ -878,6 +905,7 @@ int main(int /*argc*/, const char * /*argv*/[]) {
...
@@ -878,6 +905,7 @@ int main(int /*argc*/, const char * /*argv*/[]) {
ErrorTest
();
ErrorTest
();
ScientificTest
();
ScientificTest
();
EnumStringsTest
();
EnumStringsTest
();
IntegerOutOfRangeTest
();
UnicodeTest
();
UnicodeTest
();
UnknownFieldsTest
();
UnknownFieldsTest
();
...
...
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