BIND 10 trac2571, updated. 9e6c81fa228570d6476d1cd7b8ead3a9e89e9301 Change from char to int when we need special character values.
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Dec 21 09:15:03 UTC 2012
The branch, trac2571 has been updated
via 9e6c81fa228570d6476d1cd7b8ead3a9e89e9301 (commit)
from c8dcb23d366d559cb685b64514f49d7222df3335 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 9e6c81fa228570d6476d1cd7b8ead3a9e89e9301
Author: Shane Kerr <shane at isc.org>
Date: Fri Dec 21 10:11:05 2012 +0100
Change from char to int when we need special character values.
In cases where we use values outside of normal character range (-128
to 127 or 0 to 255) to indicate special things, like EOF, we need to
insure that we can hold these values. To do that, we use an int.
It turns out that the default type conversions also meant that our
JSON conversion from strings would break in some cases. A test was
added to show that, and to confirm the fix.
-----------------------------------------------------------------------
Summary of changes:
src/lib/cc/data.cc | 21 ++++++++++-----------
src/lib/cc/tests/data_unittests.cc | 1 +
tests/tools/perfdhcp/command_options.cc | 2 +-
3 files changed, 12 insertions(+), 12 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/cc/data.cc b/src/lib/cc/data.cc
index 4a37087..0bad756 100644
--- a/src/lib/cc/data.cc
+++ b/src/lib/cc/data.cc
@@ -240,7 +240,7 @@ Element::createMap() {
//
namespace {
bool
-char_in(const char c, const char *chars) {
+char_in(const int c, const char *chars) {
for (size_t i = 0; i < strlen(chars); ++i) {
if (chars[i] == c) {
return (true);
@@ -251,7 +251,7 @@ char_in(const char c, const char *chars) {
void
skip_chars(std::istream &in, const char *chars, int& line, int& pos) {
- char c = in.peek();
+ int c = in.peek();
while (char_in(c, chars) && c != EOF) {
if (c == '\n') {
++line;
@@ -273,7 +273,7 @@ void
skip_to(std::istream &in, const std::string& file, int& line,
int& pos, const char* chars, const char* may_skip="")
{
- char c = in.get();
+ int c = in.get();
++pos;
while (c != EOF) {
if (c == '\n') {
@@ -296,7 +296,7 @@ skip_to(std::istream &in, const std::string& file, int& line,
--pos;
return;
} else {
- throwJSONError(std::string("'") + c + "' read, one of \"" + chars + "\" expected", file, line, pos);
+ throwJSONError(std::string("'") + std::string(1, c) + "' read, one of \"" + chars + "\" expected", file, line, pos);
}
}
throwJSONError(std::string("EOF read, one of \"") + chars + "\" expected", file, line, pos);
@@ -308,9 +308,8 @@ std::string
str_from_stringstream(std::istream &in, const std::string& file, const int line,
int& pos) throw (JSONError)
{
- char c;
std::stringstream ss;
- c = in.get();
+ int c = in.get();
++pos;
if (c == '"') {
c = in.get();
@@ -354,7 +353,7 @@ str_from_stringstream(std::istream &in, const std::string& file, const int line,
in.get();
++pos;
}
- ss << c;
+ ss.put(c);
c = in.get();
++pos;
}
@@ -461,7 +460,7 @@ ElementPtr
from_stringstream_list(std::istream &in, const std::string& file, int& line,
int& pos)
{
- char c = 0;
+ int c = 0;
ElementPtr list = Element::createList();
ConstElementPtr cur_list_element;
@@ -484,7 +483,7 @@ from_stringstream_map(std::istream &in, const std::string& file, int& line,
{
ElementPtr map = Element::createMap();
skip_chars(in, WHITESPACE, line, pos);
- char c = in.peek();
+ int c = in.peek();
if (c == EOF) {
throwJSONError(std::string("Unterminated map, <string> or } expected"), file, line, pos);
} else if (c == '}') {
@@ -578,7 +577,7 @@ ElementPtr
Element::fromJSON(std::istream &in, const std::string& file, int& line,
int& pos) throw(JSONError)
{
- char c = 0;
+ int c = 0;
ElementPtr element;
bool el_read = false;
skip_chars(in, WHITESPACE, line, pos);
@@ -633,7 +632,7 @@ Element::fromJSON(std::istream &in, const std::string& file, int& line,
case EOF:
break;
default:
- throwJSONError(std::string("error: unexpected character ") + c, file, line, pos);
+ throwJSONError(std::string("error: unexpected character ") + std::string(1, c), file, line, pos);
break;
}
}
diff --git a/src/lib/cc/tests/data_unittests.cc b/src/lib/cc/tests/data_unittests.cc
index 1565418..9c41a31 100644
--- a/src/lib/cc/tests/data_unittests.cc
+++ b/src/lib/cc/tests/data_unittests.cc
@@ -91,6 +91,7 @@ TEST(Element, from_and_to_json) {
sv.push_back("-1");
sv.push_back("-1.234");
sv.push_back("-123.456");
+ sv.push_back("\"\xFF\"");
BOOST_FOREACH(const std::string& s, sv) {
// test << operator, which uses Element::str()
diff --git a/tests/tools/perfdhcp/command_options.cc b/tests/tools/perfdhcp/command_options.cc
index 9de07ca..f770373 100644
--- a/tests/tools/perfdhcp/command_options.cc
+++ b/tests/tools/perfdhcp/command_options.cc
@@ -134,7 +134,7 @@ CommandOptions::parse(int argc, char** const argv) {
bool
CommandOptions::initialize(int argc, char** argv) {
- char opt = 0; // Subsequent options returned by getopt()
+ int opt = 0; // Subsequent options returned by getopt()
std::string drop_arg; // Value of -D<value>argument
size_t percent_loc = 0; // Location of % sign in -D<value>
double drop_percent = 0; // % value (1..100) in -D<value%>
More information about the bind10-changes
mailing list