Fixing up for #define instead of typedef in secure allocators

This commit is contained in:
Christopher Dawes
2016-03-07 08:29:59 +00:00
committed by Christopher Dunn
parent 5da29e2707
commit 75570d7068
10 changed files with 327 additions and 299 deletions

View File

@@ -110,9 +110,9 @@ bool Reader::parse(std::istream& sin, Value& root, bool collectComments) {
// Those would allow streamed input from a file, if parse() were a
// template function.
// Since std::string is reference-counted, this at least does not
// Since JSONCPP_STRING is reference-counted, this at least does not
// create an extra copy.
std::string doc;
JSONCPP_STRING doc;
std::getline(sin, doc, (char)EOF);
return parse(doc, root, collectComments);
}
@@ -368,8 +368,8 @@ bool Reader::readComment() {
return true;
}
static std::string normalizeEOL(Reader::Location begin, Reader::Location end) {
std::string normalized;
static JSONCPP_STRING normalizeEOL(Reader::Location begin, Reader::Location end) {
JSONCPP_STRING normalized;
normalized.reserve(static_cast<size_t>(end - begin));
Reader::Location current = begin;
while (current != end) {
@@ -390,7 +390,7 @@ static std::string normalizeEOL(Reader::Location begin, Reader::Location end) {
void
Reader::addComment(Location begin, Location end, CommentPlacement placement) {
assert(collectComments_);
const std::string& normalized = normalizeEOL(begin, end);
const JSONCPP_STRING& normalized = normalizeEOL(begin, end);
if (placement == commentAfterOnSameLine) {
assert(lastValue_ != 0);
lastValue_->setComment(normalized, placement);
@@ -460,7 +460,7 @@ bool Reader::readString() {
bool Reader::readObject(Token& tokenStart) {
Token tokenName;
std::string name;
JSONCPP_STRING name;
Value init(objectValue);
currentValue().swapPayload(init);
currentValue().setOffsetStart(tokenStart.start_ - begin_);
@@ -480,7 +480,7 @@ bool Reader::readObject(Token& tokenStart) {
Value numberName;
if (!decodeNumber(tokenName, numberName))
return recoverFromError(tokenObjectEnd);
name = numberName.asString();
name = JSONCPP_STRING(numberName.asCString());
} else {
break;
}
@@ -616,10 +616,10 @@ bool Reader::decodeDouble(Token& token) {
bool Reader::decodeDouble(Token& token, Value& decoded) {
double value = 0;
std::string buffer(token.start_, token.end_);
JSONCPP_STRING buffer(token.start_, token.end_);
JSONCPP_ISTRINGSTREAM is(buffer);
if (!(is >> value))
return addError("'" + std::string(token.start_, token.end_) +
return addError("'" + JSONCPP_STRING(token.start_, token.end_) +
"' is not a number.",
token);
decoded = value;
@@ -627,7 +627,7 @@ bool Reader::decodeDouble(Token& token, Value& decoded) {
}
bool Reader::decodeString(Token& token) {
std::string decoded_string;
JSONCPP_STRING decoded_string;
if (!decodeString(token, decoded_string))
return false;
Value decoded(decoded_string);
@@ -637,7 +637,7 @@ bool Reader::decodeString(Token& token) {
return true;
}
bool Reader::decodeString(Token& token, std::string& decoded) {
bool Reader::decodeString(Token& token, JSONCPP_STRING& decoded) {
decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
Location current = token.start_ + 1; // skip '"'
Location end = token.end_ - 1; // do not include '"'
@@ -749,7 +749,7 @@ bool Reader::decodeUnicodeEscapeSequence(Token& token,
}
bool
Reader::addError(const std::string& message, Token& token, Location extra) {
Reader::addError(const JSONCPP_STRING& message, Token& token, Location extra) {
ErrorInfo info;
info.token_ = token;
info.message_ = message;
@@ -771,7 +771,7 @@ bool Reader::recoverFromError(TokenType skipUntilToken) {
return false;
}
bool Reader::addErrorAndRecover(const std::string& message,
bool Reader::addErrorAndRecover(const JSONCPP_STRING& message,
Token& token,
TokenType skipUntilToken) {
addError(message, token);
@@ -809,7 +809,7 @@ void Reader::getLocationLineAndColumn(Location location,
++line;
}
std::string Reader::getLocationLineAndColumn(Location location) const {
JSONCPP_STRING Reader::getLocationLineAndColumn(Location location) const {
int line, column;
getLocationLineAndColumn(location, line, column);
char buffer[18 + 16 + 16 + 1];
@@ -818,12 +818,12 @@ std::string Reader::getLocationLineAndColumn(Location location) const {
}
// Deprecated. Preserved for backward compatibility
std::string Reader::getFormatedErrorMessages() const {
JSONCPP_STRING Reader::getFormatedErrorMessages() const {
return getFormattedErrorMessages();
}
std::string Reader::getFormattedErrorMessages() const {
std::string formattedMessage;
JSONCPP_STRING Reader::getFormattedErrorMessages() const {
JSONCPP_STRING formattedMessage;
for (Errors::const_iterator itError = errors_.begin();
itError != errors_.end();
++itError) {
@@ -853,7 +853,7 @@ std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
return allErrors;
}
bool Reader::pushError(const Value& value, const std::string& message) {
bool Reader::pushError(const Value& value, const JSONCPP_STRING& message) {
ptrdiff_t const length = end_ - begin_;
if(value.getOffsetStart() > length
|| value.getOffsetLimit() > length)
@@ -870,7 +870,7 @@ bool Reader::pushError(const Value& value, const std::string& message) {
return true;
}
bool Reader::pushError(const Value& value, const std::string& message, const Value& extra) {
bool Reader::pushError(const Value& value, const JSONCPP_STRING& message, const Value& extra) {
ptrdiff_t const length = end_ - begin_;
if(value.getOffsetStart() > length
|| value.getOffsetLimit() > length
@@ -923,7 +923,7 @@ public:
struct StructuredError {
ptrdiff_t offset_start;
ptrdiff_t offset_limit;
std::string message;
JSONCPP_STRING message;
};
OurReader(OurFeatures const& features);
@@ -931,10 +931,10 @@ public:
const char* endDoc,
Value& root,
bool collectComments = true);
std::string getFormattedErrorMessages() const;
JSONCPP_STRING getFormattedErrorMessages() const;
std::vector<StructuredError> getStructuredErrors() const;
bool pushError(const Value& value, const std::string& message);
bool pushError(const Value& value, const std::string& message, const Value& extra);
bool pushError(const Value& value, const JSONCPP_STRING& message);
bool pushError(const Value& value, const JSONCPP_STRING& message, const Value& extra);
bool good() const;
private:
@@ -971,7 +971,7 @@ private:
class ErrorInfo {
public:
Token token_;
std::string message_;
JSONCPP_STRING message_;
Location extra_;
};
@@ -992,7 +992,7 @@ private:
bool decodeNumber(Token& token);
bool decodeNumber(Token& token, Value& decoded);
bool decodeString(Token& token);
bool decodeString(Token& token, std::string& decoded);
bool decodeString(Token& token, JSONCPP_STRING& decoded);
bool decodeDouble(Token& token);
bool decodeDouble(Token& token, Value& decoded);
bool decodeUnicodeCodePoint(Token& token,
@@ -1003,9 +1003,9 @@ private:
Location& current,
Location end,
unsigned int& unicode);
bool addError(const std::string& message, Token& token, Location extra = 0);
bool addError(const JSONCPP_STRING& message, Token& token, Location extra = 0);
bool recoverFromError(TokenType skipUntilToken);
bool addErrorAndRecover(const std::string& message,
bool addErrorAndRecover(const JSONCPP_STRING& message,
Token& token,
TokenType skipUntilToken);
void skipUntilSpace();
@@ -1013,20 +1013,20 @@ private:
Char getNextChar();
void
getLocationLineAndColumn(Location location, int& line, int& column) const;
std::string getLocationLineAndColumn(Location location) const;
JSONCPP_STRING getLocationLineAndColumn(Location location) const;
void addComment(Location begin, Location end, CommentPlacement placement);
void skipCommentTokens(Token& token);
typedef std::stack<Value*> Nodes;
Nodes nodes_;
Errors errors_;
std::string document_;
JSONCPP_STRING document_;
Location begin_;
Location end_;
Location current_;
Location lastValueEnd_;
Value* lastValue_;
std::string commentsBefore_;
JSONCPP_STRING commentsBefore_;
int stackDepth_;
OurFeatures const features_;
@@ -1350,7 +1350,7 @@ bool OurReader::readComment() {
void
OurReader::addComment(Location begin, Location end, CommentPlacement placement) {
assert(collectComments_);
const std::string& normalized = normalizeEOL(begin, end);
const JSONCPP_STRING& normalized = normalizeEOL(begin, end);
if (placement == commentAfterOnSameLine) {
assert(lastValue_ != 0);
lastValue_->setComment(normalized, placement);
@@ -1437,7 +1437,7 @@ bool OurReader::readStringSingleQuote() {
bool OurReader::readObject(Token& tokenStart) {
Token tokenName;
std::string name;
JSONCPP_STRING name;
Value init(objectValue);
currentValue().swapPayload(init);
currentValue().setOffsetStart(tokenStart.start_ - begin_);
@@ -1469,7 +1469,7 @@ bool OurReader::readObject(Token& tokenStart) {
}
if (name.length() >= (1U<<30)) throwRuntimeError("keylength >= 2^30");
if (features_.rejectDupKeys_ && currentValue().isMember(name)) {
std::string msg = "Duplicate key: '" + name + "'";
JSONCPP_STRING msg = "Duplicate key: '" + name + "'";
return addErrorAndRecover(
msg, tokenName, tokenObjectEnd);
}
@@ -1620,12 +1620,12 @@ bool OurReader::decodeDouble(Token& token, Value& decoded) {
buffer[length] = 0;
count = sscanf(buffer, format, &value);
} else {
std::string buffer(token.start_, token.end_);
JSONCPP_STRING buffer(token.start_, token.end_);
count = sscanf(buffer.c_str(), format, &value);
}
if (count != 1)
return addError("'" + std::string(token.start_, token.end_) +
return addError("'" + JSONCPP_STRING(token.start_, token.end_) +
"' is not a number.",
token);
decoded = value;
@@ -1633,7 +1633,7 @@ bool OurReader::decodeDouble(Token& token, Value& decoded) {
}
bool OurReader::decodeString(Token& token) {
std::string decoded_string;
JSONCPP_STRING decoded_string;
if (!decodeString(token, decoded_string))
return false;
Value decoded(decoded_string);
@@ -1643,7 +1643,7 @@ bool OurReader::decodeString(Token& token) {
return true;
}
bool OurReader::decodeString(Token& token, std::string& decoded) {
bool OurReader::decodeString(Token& token, JSONCPP_STRING& decoded) {
decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
Location current = token.start_ + 1; // skip '"'
Location end = token.end_ - 1; // do not include '"'
@@ -1755,7 +1755,7 @@ bool OurReader::decodeUnicodeEscapeSequence(Token& token,
}
bool
OurReader::addError(const std::string& message, Token& token, Location extra) {
OurReader::addError(const JSONCPP_STRING& message, Token& token, Location extra) {
ErrorInfo info;
info.token_ = token;
info.message_ = message;
@@ -1777,7 +1777,7 @@ bool OurReader::recoverFromError(TokenType skipUntilToken) {
return false;
}
bool OurReader::addErrorAndRecover(const std::string& message,
bool OurReader::addErrorAndRecover(const JSONCPP_STRING& message,
Token& token,
TokenType skipUntilToken) {
addError(message, token);
@@ -1815,7 +1815,7 @@ void OurReader::getLocationLineAndColumn(Location location,
++line;
}
std::string OurReader::getLocationLineAndColumn(Location location) const {
JSONCPP_STRING OurReader::getLocationLineAndColumn(Location location) const {
int line, column;
getLocationLineAndColumn(location, line, column);
char buffer[18 + 16 + 16 + 1];
@@ -1823,8 +1823,8 @@ std::string OurReader::getLocationLineAndColumn(Location location) const {
return buffer;
}
std::string OurReader::getFormattedErrorMessages() const {
std::string formattedMessage;
JSONCPP_STRING OurReader::getFormattedErrorMessages() const {
JSONCPP_STRING formattedMessage;
for (Errors::const_iterator itError = errors_.begin();
itError != errors_.end();
++itError) {
@@ -1854,7 +1854,7 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
return allErrors;
}
bool OurReader::pushError(const Value& value, const std::string& message) {
bool OurReader::pushError(const Value& value, const JSONCPP_STRING& message) {
ptrdiff_t length = end_ - begin_;
if(value.getOffsetStart() > length
|| value.getOffsetLimit() > length)
@@ -1871,7 +1871,7 @@ bool OurReader::pushError(const Value& value, const std::string& message) {
return true;
}
bool OurReader::pushError(const Value& value, const std::string& message, const Value& extra) {
bool OurReader::pushError(const Value& value, const JSONCPP_STRING& message, const Value& extra) {
ptrdiff_t length = end_ - begin_;
if(value.getOffsetStart() > length
|| value.getOffsetLimit() > length
@@ -1906,7 +1906,7 @@ public:
{}
bool parse(
char const* beginDoc, char const* endDoc,
Value* root, std::string* errs) override {
Value* root, JSONCPP_STRING* errs) override {
bool ok = reader_.parse(beginDoc, endDoc, *root, collectComments_);
if (errs) {
*errs = reader_.getFormattedErrorMessages();
@@ -1936,7 +1936,7 @@ CharReader* CharReaderBuilder::newCharReader() const
features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool();
return new OurCharReader(collectComments, features);
}
static void getValidReaderKeys(std::set<std::string>* valid_keys)
static void getValidReaderKeys(std::set<JSONCPP_STRING>* valid_keys)
{
valid_keys->clear();
valid_keys->insert("collectComments");
@@ -1955,19 +1955,19 @@ bool CharReaderBuilder::validate(Json::Value* invalid) const
Json::Value my_invalid;
if (!invalid) invalid = &my_invalid; // so we do not need to test for NULL
Json::Value& inv = *invalid;
std::set<std::string> valid_keys;
std::set<JSONCPP_STRING> valid_keys;
getValidReaderKeys(&valid_keys);
Value::Members keys = settings_.getMemberNames();
size_t n = keys.size();
for (size_t i = 0; i < n; ++i) {
std::string const& key = keys[i];
JSONCPP_STRING const& key = keys[i];
if (valid_keys.find(key) == valid_keys.end()) {
inv[key] = settings_[key];
}
}
return 0u == inv.size();
}
Value& CharReaderBuilder::operator[](std::string key)
Value& CharReaderBuilder::operator[](JSONCPP_STRING key)
{
return settings_[key];
}
@@ -2008,11 +2008,11 @@ void CharReaderBuilder::setDefaults(Json::Value* settings)
bool parseFromStream(
CharReader::Factory const& fact, JSONCPP_ISTREAM& sin,
Value* root, std::string* errs)
Value* root, JSONCPP_STRING* errs)
{
JSONCPP_OSTRINGSTREAM ssin;
ssin << sin.rdbuf();
std::string doc = ssin.str();
JSONCPP_STRING doc = ssin.str();
char const* begin = doc.data();
char const* end = begin + doc.size();
// Note that we do not actually need a null-terminator.
@@ -2022,7 +2022,7 @@ bool parseFromStream(
JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM& sin, Value& root) {
CharReaderBuilder b;
std::string errs;
JSONCPP_STRING errs;
bool ok = parseFromStream(b, sin, &root, &errs);
if (!ok) {
fprintf(stderr,