From 40da1ed572d60e9c7cc2fe1ca4175e30682f5a9d Mon Sep 17 00:00:00 2001 From: brian-peloton Date: Tue, 23 May 2017 16:22:57 -0700 Subject: Removing undefined behavior and compiler warnings (#1315) * Comment out unused arguments. These last few are all that's needed to compile with -Wunused-arguments. * Fix missing struct field initializer. With this fix, everything compiles with -Wmissing-field-initializers. * Add support for disabling unaligned memory accesses on x86 too. ubsan doesn't like these because they are technically undefined behavior, so -DGOOGLE_PROTOBUF_DONT_USE_UNALIGNED will disable them easily. * Avoid undefined integer overflow. ubsan catches all of these. --- src/google/protobuf/io/tokenizer_unittest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/google/protobuf/io') diff --git a/src/google/protobuf/io/tokenizer_unittest.cc b/src/google/protobuf/io/tokenizer_unittest.cc index cadeb696..e55288e2 100644 --- a/src/google/protobuf/io/tokenizer_unittest.cc +++ b/src/google/protobuf/io/tokenizer_unittest.cc @@ -341,7 +341,7 @@ inline std::ostream& operator<<(std::ostream& out, MultiTokenCase kMultiTokenCases[] = { // Test empty input. { "", { - { Tokenizer::TYPE_END , "" , 0, 0 }, + { Tokenizer::TYPE_END , "" , 0, 0, 0 }, }}, // Test all token types at the same time. -- cgit v1.2.3 From 81142e162b7eea2c3f3483a11ce13a7fb5c20b88 Mon Sep 17 00:00:00 2001 From: Brad Larson Date: Wed, 12 Jul 2017 14:45:19 -0500 Subject: Fix build when using -Werror=undef Correct a couple places where macros were being checked when they might not exist in some cases. Fixes #3356. --- src/google/protobuf/io/coded_stream.h | 2 +- src/google/protobuf/stubs/hash.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/google/protobuf/io') diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index 20d86143..9f1cf88c 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -1434,7 +1434,7 @@ inline bool CodedInputStream::IsFlat() const { } // namespace protobuf -#if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER) +#if defined(_MSC_VER) && _MSC_VER >= 1300 && !defined(__INTEL_COMPILER) #pragma runtime_checks("c", restore) #endif // _MSC_VER && !defined(__INTEL_COMPILER) diff --git a/src/google/protobuf/stubs/hash.h b/src/google/protobuf/stubs/hash.h index 5924de98..612b5861 100644 --- a/src/google/protobuf/stubs/hash.h +++ b/src/google/protobuf/stubs/hash.h @@ -42,7 +42,7 @@ #define GOOGLE_PROTOBUF_HAVE_HASH_SET 1 // Use C++11 unordered_{map|set} if available. -#if ((_LIBCPP_STD_VER >= 11) || \ +#if ((defined(_LIBCPP_STD_VER) && _LIBCPP_STD_VER >= 11) || \ (((__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X)) && \ (__GLIBCXX__ > 20090421))) # define GOOGLE_PROTOBUF_HAS_CXX11_HASH -- cgit v1.2.3