Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
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
protobuf
Commits
17b6fc31
Commit
17b6fc31
authored
May 04, 2016
by
Feng Xiao
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1409 from eeight/fix_enum_corruption
Fix bug with silent message corruption in LITE_RUNTIME.
parents
72e162ce
f4f9aec5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
2 deletions
+50
-2
cpp_enum_field.cc
src/google/protobuf/compiler/cpp/cpp_enum_field.cc
+4
-2
lite_unittest.cc
src/google/protobuf/lite_unittest.cc
+27
-0
unittest_lite.proto
src/google/protobuf/unittest_lite.proto
+19
-0
No files found.
src/google/protobuf/compiler/cpp/cpp_enum_field.cc
View file @
17b6fc31
...
...
@@ -36,6 +36,7 @@
#include <google/protobuf/compiler/cpp/cpp_helpers.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/wire_format.h>
namespace
google
{
namespace
protobuf
{
...
...
@@ -141,8 +142,9 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
}
else
{
printer
->
Print
(
"} else {
\n
"
" unknown_fields_stream.WriteVarint32(tag);
\n
"
" unknown_fields_stream.WriteVarint32(value);
\n
"
);
" unknown_fields_stream.WriteVarint32($tag$);
\n
"
" unknown_fields_stream.WriteVarint32(value);
\n
"
,
"tag"
,
SimpleItoa
(
internal
::
WireFormat
::
MakeTag
(
descriptor_
)));
}
printer
->
Print
(
variables_
,
"}
\n
"
);
...
...
src/google/protobuf/lite_unittest.cc
View file @
17b6fc31
...
...
@@ -686,6 +686,33 @@ int main(int argc, char* argv[]) {
EXPECT_TRUE
(
map_message
.
IsInitialized
());
}
{
// Check that adding more values to enum does not corrupt message
// when passed through an old client.
protobuf_unittest
::
V2MessageLite
v2_message
;
v2_message
.
set_int_field
(
800
);
// Set enum field to the value not understood by the old client.
v2_message
.
set_enum_field
(
protobuf_unittest
::
V2_SECOND
);
string
v2_bytes
=
v2_message
.
SerializeAsString
();
protobuf_unittest
::
V1MessageLite
v1_message
;
v1_message
.
ParseFromString
(
v2_bytes
);
EXPECT_TRUE
(
v1_message
.
IsInitialized
());
EXPECT_EQ
(
v1_message
.
int_field
(),
v2_message
.
int_field
());
// V1 client does not understand V2_SECOND value, so it discards it and
// uses default value instead.
EXPECT_EQ
(
v1_message
.
enum_field
(),
protobuf_unittest
::
V1_FIRST
);
// However, when re-serialized, it should preserve enum value.
string
v1_bytes
=
v1_message
.
SerializeAsString
();
protobuf_unittest
::
V2MessageLite
same_v2_message
;
same_v2_message
.
ParseFromString
(
v1_bytes
);
EXPECT_EQ
(
v2_message
.
int_field
(),
same_v2_message
.
int_field
());
EXPECT_EQ
(
v2_message
.
enum_field
(),
same_v2_message
.
enum_field
());
}
std
::
cout
<<
"PASS"
<<
std
::
endl
;
return
0
;
}
src/google/protobuf/unittest_lite.proto
View file @
17b6fc31
...
...
@@ -386,3 +386,22 @@ message TestEmptyMessageLite{
message
TestEmptyMessageWithExtensionsLite
{
extensions
1
to
max
;
}
enum
V1EnumLite
{
V1_FIRST
=
1
;
}
enum
V2EnumLite
{
V2_FIRST
=
1
;
V2_SECOND
=
2
;
}
message
V1MessageLite
{
required
int32
int_field
=
1
;
optional
V1EnumLite
enum_field
=
2
[
default
=
V1_FIRST
];
}
message
V2MessageLite
{
required
int32
int_field
=
1
;
optional
V2EnumLite
enum_field
=
2
[
default
=
V2_FIRST
];
}
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