From 30013b4ff80dd7d4fde56e1b2b8b988feed6437f Mon Sep 17 00:00:00 2001 From: Chris Pickett Date: Tue, 5 Jan 2016 13:38:03 -0600 Subject: [PATCH 1/3] Fixed MS static analysis warnings Cleaned up a few warnings to allow VS2012 to compile idl_parser and idl_gen_text (for exporting binary protobuf blobs as JSON) cleanly under static analysis. --- include/flatbuffers/util.h | 3 +++ src/idl_parser.cpp | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/flatbuffers/util.h b/include/flatbuffers/util.h index ba73d67bd..f3fbef497 100644 --- a/include/flatbuffers/util.h +++ b/include/flatbuffers/util.h @@ -210,6 +210,9 @@ inline void EnsureDirExists(const std::string &filepath) { auto parent = StripFileName(filepath); if (parent.length()) EnsureDirExists(parent); #ifdef _WIN32 + #ifdef _MSC_VER + #pragma warning(suppress: 6031) + #endif _mkdir(filepath.c_str()); #else mkdir(filepath.c_str(), S_IRWXU|S_IRGRP|S_IXGRP); diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index b533d213e..91ada0e6d 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -191,7 +191,7 @@ std::string Parser::TokenToStringId(int t) { // Parses exactly nibbles worth of hex digits into a number, or error. CheckedError Parser::ParseHexNum(int nibbles, int64_t *val) { for (int i = 0; i < nibbles; i++) - if (!isxdigit(cursor_[i])) + if (!isxdigit(static_cast(cursor_[i]))) return Error("escape code must be followed by " + NumToString(nibbles) + " hex digits"); std::string target(cursor_, cursor_ + nibbles); @@ -214,7 +214,7 @@ CheckedError Parser::Next() { case '{': case '}': case '(': case ')': case '[': case ']': case ',': case ':': case ';': case '=': return NoError(); case '.': - if(!isdigit(*cursor_)) return NoError(); + if(!isdigit(static_cast(*cursor_))) return NoError(); return Error("floating point constant can\'t start with \".\""); case '\"': case '\'': From cfd6e7dea8dd5e30374a8528dd420f43f0dfc1ee Mon Sep 17 00:00:00 2001 From: Chris Pickett Date: Wed, 6 Jan 2016 12:04:46 -0600 Subject: [PATCH 2/3] Documented what the suppressed warning is about --- include/flatbuffers/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/flatbuffers/util.h b/include/flatbuffers/util.h index f3fbef497..41a6ce07e 100644 --- a/include/flatbuffers/util.h +++ b/include/flatbuffers/util.h @@ -211,7 +211,7 @@ inline void EnsureDirExists(const std::string &filepath) { if (parent.length()) EnsureDirExists(parent); #ifdef _WIN32 #ifdef _MSC_VER - #pragma warning(suppress: 6031) + #pragma warning(suppress: 6031) // "return value ignored: could return unexpected value" #endif _mkdir(filepath.c_str()); #else From 178f768f7f8fb2cb96027fe2ec029be96bbca504 Mon Sep 17 00:00:00 2001 From: Chris Pickett Date: Wed, 6 Jan 2016 14:21:18 -0600 Subject: [PATCH 3/3] Changed how the SA warning is suppressed to avoid pragma stuff --- include/flatbuffers/util.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/flatbuffers/util.h b/include/flatbuffers/util.h index 41a6ce07e..8af592302 100644 --- a/include/flatbuffers/util.h +++ b/include/flatbuffers/util.h @@ -210,10 +210,7 @@ inline void EnsureDirExists(const std::string &filepath) { auto parent = StripFileName(filepath); if (parent.length()) EnsureDirExists(parent); #ifdef _WIN32 - #ifdef _MSC_VER - #pragma warning(suppress: 6031) // "return value ignored: could return unexpected value" - #endif - _mkdir(filepath.c_str()); + (void)_mkdir(filepath.c_str()); #else mkdir(filepath.c_str(), S_IRWXU|S_IRGRP|S_IXGRP); #endif