Skip to content

Commit

Permalink
Disable conditional expression is constant warning (C4127) inside pro…
Browse files Browse the repository at this point in the history
…tobuf
  • Loading branch information
Sil3ntStorm committed Aug 29, 2021
1 parent a3e5587 commit 1473d74
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/google/protobuf/port_def.inc
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,8 @@
#pragma warning(disable : 4073)
// To silence the fact that we will pop this push from another file
#pragma warning(disable : 5031)
// Conditional expression is constant
#pragma warning(disable: 4127)
#endif

// We don't want code outside port_def doing complex testing, so
Expand Down
7 changes: 3 additions & 4 deletions src/google/protobuf/stubs/stringprintf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@ namespace google {
namespace protobuf {

#ifdef _MSC_VER
enum { IS_COMPILER_MSVC = 1 };
#ifndef va_copy
// Define va_copy for MSVC. This is a hack, assuming va_list is simply a
// pointer into the stack and is safe to copy.
#define va_copy(dest, src) ((dest) = (src))
#endif
#else
enum { IS_COMPILER_MSVC = 0 };
#endif

void StringAppendV(std::string* dst, const char* format, va_list ap) {
Expand All @@ -74,13 +71,15 @@ void StringAppendV(std::string* dst, const char* format, va_list ap) {
return;
}

if (IS_COMPILER_MSVC) {
#ifdef _MSC_VER
{
// Error or MSVC running out of space. MSVC 8.0 and higher
// can be asked about space needed with the special idiom below:
va_copy(backup_ap, ap);
result = vsnprintf(nullptr, 0, format, backup_ap);
va_end(backup_ap);
}
#endif

if (result < 0) {
// Just an error.
Expand Down

0 comments on commit 1473d74

Please sign in to comment.