Fix build issues and compiler warnings with MSVC 2013

This commit is contained in:
Tristan Penman 2015-10-17 08:27:39 +11:00
parent 9b3779a57b
commit 9216f5f6f1
7 changed files with 26 additions and 9 deletions

View File

@ -1,6 +1,7 @@
cmake_minimum_required (VERSION 2.6)
project (valijson)
add_definitions(-DBOOST_ALL_DYN_LINK)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
@ -15,6 +16,7 @@ add_library(jsoncpp
)
# Build local gtest
set(gtest_force_shared_crt ON)
add_subdirectory(thirdparty/gtest-1.7.0)
# Include path

View File

@ -132,7 +132,13 @@ inline AdapterType resolveJsonPointer(
"out of bounds; actual token: " + referenceToken);
}
itr.advance(index);
if (index > std::numeric_limits<ptrdiff_t>::max()) {
throw std::runtime_error("Array index out of bounds; hard "
"limit is " + boost::lexical_cast<std::string>(
std::numeric_limits<ptrdiff_t>::max()));
}
itr.advance(static_cast<ptrdiff_t>(index));
// Recursively process the remaining tokens
return resolveJsonPointer(*itr, jsonPointer, jsonPointerNext);

View File

@ -24,8 +24,13 @@ inline bool loadFile(const std::string &path, std::string &dest)
// Allocate space for file contents
file.seekg(0, std::ios::end);
const std::streamoff offset = file.tellg();
if (offset < 0 || offset > std::numeric_limits<unsigned int>::max()) {
return false;
}
dest.clear();
dest.reserve(file.tellg());
dest.reserve(static_cast<unsigned int>(offset));
// Assign file contents to destination string
file.seekg(0, std::ios::beg);

View File

@ -21,7 +21,7 @@ inline bool loadDocument(const std::string &path, Json::Value &document)
bool parsingSuccessful = reader.parse(file, document);
if (!parsingSuccessful) {
std::cerr << "Jsoncpp parser failed to parse the document:" << std::endl
<< reader.getFormatedErrorMessages();
<< reader.getFormattedErrorMessages();
return false;
}

View File

@ -7,10 +7,14 @@
#include <boost/property_tree/ptree.hpp>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
#include <boost/property_tree/json_parser.hpp>
#pragma clang diagnostic pop
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wshorten-64-to-32"
# include <boost/property_tree/json_parser.hpp>
# pragma clang diagnostic pop
#else
# include <boost/property_tree/json_parser.hpp>
#endif
#include <boost/property_tree/detail/json_parser_error.hpp>

View File

@ -22,7 +22,7 @@ inline bool loadDocument(const std::string &path, rapidjson::Document &document)
if (document.HasParseError()) {
std::cerr << "RapidJson failed to parse the document:" << std::endl;
std::cerr << "Parse error: " << document.GetParseError() << std::endl;
std::cerr << "Near: " << file.substr(std::max(size_t(0), document.GetErrorOffset() - 20), 40) << std::endl;
std::cerr << "Near: " << file.substr((std::max)(size_t(0), document.GetErrorOffset() - 20), 40) << std::endl;
return false;
}

View File

@ -651,7 +651,7 @@ public:
}
return false;
}
d = i;
d = static_cast<double>(i);
} else {
return true;
}