Skip to content

Commit

Permalink
Don't assume char is signed.
Browse files Browse the repository at this point in the history
It isn't always, which causes problems when trying to put negative
values into the array with C++11.
  • Loading branch information
bsilver8192 committed Sep 9, 2015
1 parent 133be3d commit 21f3d37
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/google/protobuf/compiler/cpp/cpp_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,13 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
// bytes in length". Declare a static array of characters rather than use a
// string literal.
if (breakdown_large_file && file_data.size() > 65535) {
// This has to be explicitly marked as a signed char because the generated
// code puts negative values in the array, and sometimes plain char is
// unsigned. That implicit narrowing conversion is not allowed in C++11.
// <http://stackoverflow.com/questions/4434140/narrowing-conversions-in-c0x-is-it-just-me-or-does-this-sound-like-a-breakin>
// has details on why.
printer->Print(
"static const char descriptor[] = {\n");
"static const signed char descriptor[] = {\n");
printer->Indent();

// Only write 25 bytes per line.
Expand Down

0 comments on commit 21f3d37

Please sign in to comment.