summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/fdstream.h2
-rw-r--r--lib/sha1.cpp16
-rw-r--r--src/account.h2
-rw-r--r--src/amount.cc35
-rw-r--r--src/commodity.cc4
-rw-r--r--src/derive.cc2
-rw-r--r--src/error.cc14
-rw-r--r--src/error.h8
-rw-r--r--src/expr.cc6
-rw-r--r--src/expr.h3
-rw-r--r--src/format.cc2
-rw-r--r--src/format.h10
-rw-r--r--src/global.cc2
-rw-r--r--src/item.cc2
-rw-r--r--src/option.cc2
-rw-r--r--src/parser.cc4
-rw-r--r--src/py_times.cc67
-rw-r--r--src/pyfstream.h2
-rw-r--r--src/textual.cc12
-rw-r--r--src/times.cc2
-rw-r--r--src/token.cc22
-rw-r--r--src/utils.h14
-rw-r--r--src/xact.cc3
-rw-r--r--test/unit/t_amount.cc12
24 files changed, 147 insertions, 101 deletions
diff --git a/lib/fdstream.h b/lib/fdstream.h
index a74a5781..af352c2c 100644
--- a/lib/fdstream.h
+++ b/lib/fdstream.h
@@ -68,7 +68,7 @@ class fdoutbuf : public std::streambuf {
// write one character
virtual int_type overflow (int_type c) {
if (c != EOF) {
- char z = c;
+ char z = static_cast<char>(c);
if (write (fd, &z, 1) != 1) {
return EOF;
}
diff --git a/lib/sha1.cpp b/lib/sha1.cpp
index cc2e49de..8689d711 100644
--- a/lib/sha1.cpp
+++ b/lib/sha1.cpp
@@ -552,14 +552,14 @@ void SHA1::PadMessage()
/*
* Store the message length as the last 8 octets
*/
- Message_Block[56] = (Length_High >> 24) & 0xFF;
- Message_Block[57] = (Length_High >> 16) & 0xFF;
- Message_Block[58] = (Length_High >> 8) & 0xFF;
- Message_Block[59] = (Length_High) & 0xFF;
- Message_Block[60] = (Length_Low >> 24) & 0xFF;
- Message_Block[61] = (Length_Low >> 16) & 0xFF;
- Message_Block[62] = (Length_Low >> 8) & 0xFF;
- Message_Block[63] = (Length_Low) & 0xFF;
+ Message_Block[56] = static_cast<char>((Length_High >> 24) & 0xFF);
+ Message_Block[57] = static_cast<char>((Length_High >> 16) & 0xFF);
+ Message_Block[58] = static_cast<char>((Length_High >> 8) & 0xFF);
+ Message_Block[59] = static_cast<char>((Length_High) & 0xFF);
+ Message_Block[60] = static_cast<char>((Length_Low >> 24) & 0xFF);
+ Message_Block[61] = static_cast<char>((Length_Low >> 16) & 0xFF);
+ Message_Block[62] = static_cast<char>((Length_Low >> 8) & 0xFF);
+ Message_Block[63] = static_cast<char>((Length_Low) & 0xFF);
ProcessMessageBlock();
}
diff --git a/src/account.h b/src/account.h
index 29b3c682..3bd0b9ca 100644
--- a/src/account.h
+++ b/src/account.h
@@ -78,7 +78,7 @@ class account_t : public scope_t
const string& _name = "",
const optional<string>& _note = none)
: scope_t(), parent(_parent), name(_name), note(_note),
- depth(parent ? parent->depth + 1 : 0),
+ depth(static_cast<unsigned short>(parent ? parent->depth + 1 : 0)),
known(false), data(NULL) {
TRACE_CTOR(account_t, "account_t *, const string&, const string&");
}
diff --git a/src/amount.cc b/src/amount.cc
index ded85e74..cc568bb1 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -62,7 +62,8 @@ struct amount_t::bigint_t : public supports_flags<>
mpq_init(val);
}
bigint_t(const bigint_t& other)
- : supports_flags<>(other.flags() & ~BIGINT_BULK_ALLOC),
+ : supports_flags<>(static_cast<uint_least8_t>
+ (other.flags() & ~BIGINT_BULK_ALLOC)),
prec(other.prec), ref(1) {
TRACE_CTOR(bigint_t, "copy");
mpq_init(val);
@@ -341,7 +342,8 @@ amount_t& amount_t::operator*=(const amount_t& amt)
_dup();
mpq_mul(MP(quantity), MP(quantity), MP(amt.quantity));
- quantity->prec += amt.quantity->prec;
+ quantity->prec = static_cast<precision_t>(quantity->prec +
+ amt.quantity->prec);
if (! has_commodity())
commodity_ = amt.commodity_;
@@ -349,7 +351,7 @@ amount_t& amount_t::operator*=(const amount_t& amt)
if (has_commodity() && ! keep_precision()) {
precision_t comm_prec = commodity().precision();
if (quantity->prec > comm_prec + extend_by_digits)
- quantity->prec = comm_prec + extend_by_digits;
+ quantity->prec = static_cast<precision_t>(comm_prec + extend_by_digits);
}
return *this;
@@ -377,7 +379,9 @@ amount_t& amount_t::operator/=(const amount_t& amt)
// the divide. Round up in the last position.
mpq_div(MP(quantity), MP(quantity), MP(amt.quantity));
- quantity->prec += amt.quantity->prec + quantity->prec + extend_by_digits;
+ quantity->prec =
+ static_cast<precision_t>(quantity->prec + amt.quantity->prec +
+ quantity->prec + extend_by_digits);
if (! has_commodity())
commodity_ = amt.commodity_;
@@ -390,7 +394,7 @@ amount_t& amount_t::operator/=(const amount_t& amt)
if (has_commodity() && ! keep_precision()) {
precision_t comm_prec = commodity().precision();
if (quantity->prec > comm_prec + extend_by_digits)
- quantity->prec = comm_prec + extend_by_digits;
+ quantity->prec = static_cast<precision_t>(comm_prec + extend_by_digits);
}
return *this;
@@ -837,7 +841,7 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
if (std::isdigit(c)) {
parse_quantity(in, quant);
- if (! in.eof() && ((n = in.peek()) != '\n')) {
+ if (! in.eof() && ((n = static_cast<char>(in.peek())) != '\n')) {
if (std::isspace(n))
comm_flags |= COMMODITY_STYLE_SEPARATED;
@@ -846,19 +850,20 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
if (! symbol.empty())
comm_flags |= COMMODITY_STYLE_SUFFIXED;
- if (! in.eof() && ((n = in.peek()) != '\n'))
+ if (! in.eof() && ((n = static_cast<char>(in.peek())) != '\n'))
details.parse(in);
}
} else {
commodity_t::parse_symbol(in, symbol);
- if (! in.eof() && ((n = in.peek()) != '\n')) {
- if (std::isspace(in.peek()))
+ if (! in.eof() && ((n = static_cast<char>(in.peek())) != '\n')) {
+ if (std::isspace(static_cast<char>(in.peek())))
comm_flags |= COMMODITY_STYLE_SEPARATED;
parse_quantity(in, quant);
- if (! quant.empty() && ! in.eof() && ((n = in.peek()) != '\n'))
+ if (! quant.empty() && ! in.eof() &&
+ ((n = static_cast<char>(in.peek())) != '\n'))
details.parse(in);
}
}
@@ -917,19 +922,21 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
comm_flags |= COMMODITY_STYLE_THOUSANDS;
if (last_comma > last_period) {
comm_flags |= COMMODITY_STYLE_EUROPEAN;
- quantity->prec = quant.length() - last_comma - 1;
+ quantity->prec = static_cast<precision_t>(quant.length() -
+ last_comma - 1);
} else {
- quantity->prec = quant.length() - last_period - 1;
+ quantity->prec = static_cast<precision_t>(quant.length() -
+ last_period - 1);
}
}
else if (last_comma != string::npos &&
commodity().has_flags(COMMODITY_STYLE_EUROPEAN)) {
comm_flags |= COMMODITY_STYLE_EUROPEAN;
- quantity->prec = quant.length() - last_comma - 1;
+ quantity->prec = static_cast<precision_t>(quant.length() - last_comma - 1);
}
else if (last_period != string::npos &&
! (commodity().has_flags(COMMODITY_STYLE_EUROPEAN))) {
- quantity->prec = quant.length() - last_period - 1;
+ quantity->prec = static_cast<precision_t>(quant.length() - last_period - 1);
}
else {
quantity->prec = 0;
diff --git a/src/commodity.cc b/src/commodity.cc
index 524e333a..1c849624 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -526,7 +526,7 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol)
throw_(amount_error, _("Quoted commodity symbol lacks closing quote"));
} else {
char * _p = buf;
- c = in.peek();
+ c = static_cast<char>(in.peek());
while (_p - buf < 255 && in.good() && ! in.eof() && c != '\n') {
int bytes = 0;
int size = _p - buf;
@@ -570,7 +570,7 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol)
*_p++ = c;
}
- c = in.peek();
+ c = static_cast<char>(in.peek());
}
*_p = '\0';
diff --git a/src/derive.cc b/src/derive.cc
index f4bae959..55cdcd2d 100644
--- a/src/derive.cc
+++ b/src/derive.cc
@@ -135,7 +135,7 @@ namespace {
}
else if (check_for_date &&
regex_match((*begin).to_string(), what, dow_mask)) {
- short dow = string_to_day_of_week(what[0]);
+ short dow = static_cast<short>(string_to_day_of_week(what[0]));
date_t date = CURRENT_DATE() - date_duration(1);
while (date.day_of_week() != dow)
date -= date_duration(1);
diff --git a/src/error.cc b/src/error.cc
index 653980b4..8f78334a 100644
--- a/src/error.cc
+++ b/src/error.cc
@@ -77,12 +77,12 @@ string line_context(const string& line,
return buf.str();
}
-string source_context(const path& file,
- std::size_t pos,
- std::size_t end_pos,
- const string& prefix)
+string source_context(const path& file,
+ istream_pos_type pos,
+ istream_pos_type end_pos,
+ const string& prefix)
{
- std::size_t len = end_pos - pos;
+ std::streamoff len = end_pos - pos;
if (! len || file == path("/dev/stdin"))
return _("<no source context>");
@@ -95,9 +95,9 @@ string source_context(const path& file,
in.seekg(pos, std::ios::beg);
scoped_array<char> buf(new char[len + 1]);
- in.read(buf.get(), len);
+ in.read(buf.get(), static_cast<int>(len));
assert(static_cast<std::size_t>(in.gcount()) == len);
- buf[len] = '\0';
+ buf[static_cast<int>(len)] = '\0';
bool first = true;
for (char * p = std::strtok(buf.get(), "\n");
diff --git a/src/error.h b/src/error.h
index 45c0cc68..42eab8d9 100644
--- a/src/error.h
+++ b/src/error.h
@@ -91,10 +91,10 @@ string line_context(const string& line,
std::size_t pos = 0,
std::size_t end_pos = 0);
-string source_context(const path& file,
- std::size_t pos,
- std::size_t end_pos,
- const string& prefix = "");
+string source_context(const path& file,
+ istream_pos_type pos,
+ istream_pos_type end_pos,
+ const string& prefix = "");
#define DECLARE_EXCEPTION(name, kind) \
class name : public kind { \
diff --git a/src/expr.cc b/src/expr.cc
index 2e96773b..20b52f71 100644
--- a/src/expr.cc
+++ b/src/expr.cc
@@ -92,7 +92,8 @@ void expr_t::parse(const string& _str, const uint32_t flags)
{
parser_t parser;
str = _str;
- ptr = parser.parse(str, flags);
+ ptr = parser.parse(str, parser_t::parse_flags_t
+ (static_cast<uint_least8_t>(flags)));
context = NULL;
compiled = false;
}
@@ -102,7 +103,8 @@ void expr_t::parse(std::istream& in, const uint32_t flags,
{
parser_t parser;
str = "<stream>";
- ptr = parser.parse(in, flags, original_string);
+ ptr = parser.parse(in, parser_t::parse_flags_t
+ (static_cast<uint_least8_t>(flags)), original_string);
context = NULL;
compiled = false;
}
diff --git a/src/expr.h b/src/expr.h
index 08d30316..24276cd1 100644
--- a/src/expr.h
+++ b/src/expr.h
@@ -74,7 +74,8 @@ class expr_t
public:
class op_t;
- typedef intrusive_ptr<op_t> ptr_op_t;
+ typedef intrusive_ptr<op_t> ptr_op_t;
+ typedef intrusive_ptr<const op_t> const_ptr_op_t;
enum parse_flags_enum_t {
PARSE_NORMAL = 0x00,
diff --git a/src/format.cc b/src/format.cc
index 69c0b42f..0fcbbdfd 100644
--- a/src/format.cc
+++ b/src/format.cc
@@ -145,7 +145,7 @@ format_t::element_t * format_t::parse_elements(const string& fmt)
++p;
}
- int num = 0;
+ std::size_t num = 0;
while (*p && std::isdigit(*p)) {
num *= 10;
num += *p++ - '0';
diff --git a/src/format.h b/src/format.h
index 8df2dd1e..df757eeb 100644
--- a/src/format.h
+++ b/src/format.h
@@ -69,11 +69,11 @@ class format_t : public noncopyable
EXPR,
};
- kind_t type;
- unsigned char min_width;
- unsigned char max_width;
- string chars;
- expr_t expr;
+ kind_t type;
+ std::size_t min_width;
+ std::size_t max_width;
+ string chars;
+ expr_t expr;
scoped_ptr<struct element_t> next;
diff --git a/src/global.cc b/src/global.cc
index c4b47b30..22bd5b7b 100644
--- a/src/global.cc
+++ b/src/global.cc
@@ -513,7 +513,7 @@ void handle_debug_options(int argc, char * argv[])
_log_level = LOG_TRACE; // global in utils.h
try {
// global in utils.h
- _trace_level = boost::lexical_cast<int>(argv[i + 1]);
+ _trace_level = boost::lexical_cast<uint8_t>(argv[i + 1]);
}
catch (const boost::bad_lexical_cast& e) {
throw std::logic_error(_("Argument to --trace must be an integer"));
diff --git a/src/item.cc b/src/item.cc
index 028d230e..4fcaea21 100644
--- a/src/item.cc
+++ b/src/item.cc
@@ -382,7 +382,7 @@ void print_item(std::ostream& out, const item_t& item, const string& prefix)
string item_context(const item_t& item, const string& desc)
{
- std::size_t len = item.end_pos - item.beg_pos;
+ std::streamoff len = item.end_pos - item.beg_pos;
if (! len)
return _("<no item context>");
diff --git a/src/option.cc b/src/option.cc
index 5966c582..a0701533 100644
--- a/src/option.cc
+++ b/src/option.cc
@@ -120,7 +120,7 @@ void process_environment(const char ** envp, const string& tag,
if (*q == '_')
*r++ = '-';
else
- *r++ = std::tolower(*q);
+ *r++ = static_cast<char>(std::tolower(*q));
*r = '\0';
if (*q == '=') {
diff --git a/src/parser.cc b/src/parser.cc
index fa0db199..396d3a64 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -454,7 +454,9 @@ expr_t::parser_t::parse(std::istream& in, const parse_flags_t& flags,
DEBUG("parser.error", " token kind = " << int(lookahead.kind));
DEBUG("parser.error", " token length = " << lookahead.length);
- add_error_context(line_context(*original_string, pos, end_pos));
+ add_error_context(line_context(*original_string,
+ static_cast<std::size_t>(pos),
+ static_cast<std::size_t>(end_pos)));
}
throw;
}
diff --git a/src/py_times.cc b/src/py_times.cc
index f209929a..45e7391d 100644
--- a/src/py_times.cc
+++ b/src/py_times.cc
@@ -63,14 +63,21 @@ struct date_from_python
return 0;
}
- static void construct(PyObject* obj_ptr, converter::rvalue_from_python_stage1_data* data)
+ static void construct(PyObject * obj_ptr,
+ converter::rvalue_from_python_stage1_data * data)
{
MY_PyDateTime_IMPORT;
- int y = PyDateTime_GET_YEAR(obj_ptr);
- int m = PyDateTime_GET_MONTH(obj_ptr);
- int d = PyDateTime_GET_DAY(obj_ptr);
- date* dte = new date(y,m,d);
- data->convertible = (void*)dte;
+
+ int year = PyDateTime_GET_YEAR(obj_ptr);
+ date::year_type y = gregorian::greg_year(static_cast<unsigned short>(year));
+ date::month_type m =
+ static_cast<date::month_type>(PyDateTime_GET_MONTH(obj_ptr));
+ date::day_type d =
+ static_cast<date::day_type>(PyDateTime_GET_DAY(obj_ptr));
+
+ date * dte = new date(y, m, d);
+
+ data->convertible = (void *) dte;
}
};
@@ -83,11 +90,15 @@ struct datetime_to_python
static PyObject* convert(const datetime_t& moment)
{
MY_PyDateTime_IMPORT;
+
date dte = moment.date();
datetime_t::time_duration_type tod = moment.time_of_day();
- return PyDateTime_FromDateAndTime(dte.year(), dte.month(), dte.day(),
- tod.hours(), tod.minutes(), tod.seconds(),
- tod.total_microseconds() % 1000000);
+
+ return PyDateTime_FromDateAndTime
+ (static_cast<int>(dte.year()), static_cast<int>(dte.month()),
+ static_cast<int>(dte.day()), static_cast<int>(tod.hours()),
+ static_cast<int>(tod.minutes()), static_cast<int>(tod.seconds()),
+ static_cast<int>(tod.total_microseconds() % 1000000));
}
};
@@ -100,18 +111,36 @@ struct datetime_from_python
return 0;
}
- static void construct(PyObject* obj_ptr, converter::rvalue_from_python_stage1_data* data)
+ static void construct(PyObject * obj_ptr,
+ converter::rvalue_from_python_stage1_data * data)
{
MY_PyDateTime_IMPORT;
- int y = PyDateTime_GET_YEAR(obj_ptr);
- int m = PyDateTime_GET_MONTH(obj_ptr);
- int d = PyDateTime_GET_DAY(obj_ptr);
- int h = PyDateTime_DATE_GET_HOUR(obj_ptr);
- int min = PyDateTime_DATE_GET_MINUTE(obj_ptr);
- int s = PyDateTime_DATE_GET_SECOND(obj_ptr);
- datetime_t* moment = new datetime_t(date(y,m,d),
- datetime_t::time_duration_type(h, min, s));
- data->convertible = (void*)moment;
+
+ int year = PyDateTime_GET_YEAR(obj_ptr);
+ date::year_type y = gregorian::greg_year(static_cast<unsigned short>(year));
+ date::month_type m =
+ static_cast<date::month_type>(PyDateTime_GET_MONTH(obj_ptr));
+ date::day_type d =
+ static_cast<date::day_type>(PyDateTime_GET_DAY(obj_ptr));
+
+ datetime_t::time_duration_type::hour_type h =
+ static_cast<datetime_t::time_duration_type::hour_type>
+ (PyDateTime_DATE_GET_HOUR(obj_ptr));
+ datetime_t::time_duration_type::min_type min =
+ static_cast<datetime_t::time_duration_type::min_type>
+ (PyDateTime_DATE_GET_MINUTE(obj_ptr));
+ datetime_t::time_duration_type::sec_type s =
+ static_cast<datetime_t::time_duration_type::sec_type>
+ (PyDateTime_DATE_GET_SECOND(obj_ptr));
+ datetime_t::time_duration_type::fractional_seconds_type ms =
+ static_cast<datetime_t::time_duration_type::fractional_seconds_type>
+ (PyDateTime_DATE_GET_MICROSECOND(obj_ptr)) * 1000000;
+
+ datetime_t * moment
+ = new datetime_t(date(y, m, d),
+ datetime_t::time_duration_type(h, min, s, ms));
+
+ data->convertible = (void *) moment;
}
};
diff --git a/src/pyfstream.h b/src/pyfstream.h
index 2b21b45e..5e39d38d 100644
--- a/src/pyfstream.h
+++ b/src/pyfstream.h
@@ -56,7 +56,7 @@ protected:
virtual int_type overflow (int_type c) {
if (c != EOF) {
char z[2];
- z[0] = c;
+ z[0] = static_cast<char>(c);
z[1] = '\0';
if (PyFile_WriteString(z, reinterpret_cast<PyObject *>(fo)) < 0) {
return EOF;
diff --git a/src/textual.cc b/src/textual.cc
index b3294d99..e3460202 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -919,7 +919,7 @@ post_t * instance_t::parse_post(char * line,
if (stream.eof()) {
next = NULL;
} else {
- next = skip_ws(next + stream.tellg());
+ next = skip_ws(next + static_cast<std::ptrdiff_t>(stream.tellg()));
// Parse the optional cost (@ PER-UNIT-COST, @@ TOTAL-COST)
@@ -967,7 +967,7 @@ post_t * instance_t::parse_post(char * line,
if (cstream.eof())
next = NULL;
else
- next = skip_ws(p + cstream.tellg());
+ next = skip_ws(p + static_cast<std::ptrdiff_t>(cstream.tellg()));
} else {
throw parse_error(_("Expected a cost amount"));
}
@@ -1056,7 +1056,7 @@ post_t * instance_t::parse_post(char * line,
if (stream.eof())
next = NULL;
else
- next = skip_ws(p + stream.tellg());
+ next = skip_ws(p + static_cast<std::ptrdiff_t>(stream.tellg()));
} else {
throw parse_error(_("Expected an assigned balance amount"));
}
@@ -1081,9 +1081,10 @@ post_t * instance_t::parse_post(char * line,
post->end_pos = curr_pos;
post->end_line = linenum;
- if (! tag_stack.empty())
+ if (! tag_stack.empty()) {
foreach (const string& tag, tag_stack)
post->parse_tags(tag.c_str());
+ }
TRACE_STOP(post_details, 1);
@@ -1240,9 +1241,10 @@ xact_t * instance_t::parse_xact(char * line,
xact->end_pos = curr_pos;
xact->end_line = linenum;
- if (! tag_stack.empty())
+ if (! tag_stack.empty()) {
foreach (const string& tag, tag_stack)
xact->parse_tags(tag.c_str());
+ }
TRACE_STOP(xact_details, 1);
diff --git a/src/times.cc b/src/times.cc
index 1a0b714f..7ddc7bd4 100644
--- a/src/times.cc
+++ b/src/times.cc
@@ -240,7 +240,7 @@ namespace {
inline void read_lower_word(std::istream& in, string& word) {
in >> word;
for (int i = 0, l = word.length(); i < l; i++)
- word[i] = std::tolower(word[i]);
+ word[i] = static_cast<char>(std::tolower(word[i]));
}
void parse_date_words(std::istream& in, string& word,
diff --git a/src/token.cc b/src/token.cc
index 3e14fbaf..6935bc7a 100644
--- a/src/token.cc
+++ b/src/token.cc
@@ -36,7 +36,7 @@ namespace ledger {
int expr_t::token_t::parse_reserved_word(std::istream& in)
{
- char c = in.peek();
+ char c = static_cast<char>(in.peek());
if (c == 'a' || c == 'd' || c == 'f' || c == 'o' || c == 'n' || c == 't') {
length = 0;
@@ -141,7 +141,7 @@ void expr_t::token_t::next(std::istream& in, const uint_least8_t pflags)
switch (c) {
case '&':
in.get(c);
- c = in.peek();
+ c = static_cast<char>(in.peek());
if (c == '&') {
in.get(c);
kind = KW_AND;
@@ -152,7 +152,7 @@ void expr_t::token_t::next(std::istream& in, const uint_least8_t pflags)
break;
case '|':
in.get(c);
- c = in.peek();
+ c = static_cast<char>(in.peek());
if (c == '|') {
in.get(c);
kind = KW_OR;
@@ -218,7 +218,7 @@ void expr_t::token_t::next(std::istream& in, const uint_least8_t pflags)
case '!':
in.get(c);
- c = in.peek();
+ c = static_cast<char>(in.peek());
if (c == '=') {
in.get(c);
symbol[1] = c;
@@ -258,7 +258,7 @@ void expr_t::token_t::next(std::istream& in, const uint_least8_t pflags)
break;
case ':':
in.get(c);
- c = in.peek();
+ c = static_cast<char>(in.peek());
if (c == '=') {
in.get(c);
symbol[1] = c;
@@ -291,7 +291,7 @@ void expr_t::token_t::next(std::istream& in, const uint_least8_t pflags)
case '=':
in.get(c);
- c = in.peek();
+ c = static_cast<char>(in.peek());
if (c == '~') {
in.get(c);
symbol[1] = c;
@@ -313,7 +313,7 @@ void expr_t::token_t::next(std::istream& in, const uint_least8_t pflags)
case '<':
in.get(c);
- if (in.peek() == '=') {
+ if (static_cast<char>(in.peek()) == '=') {
in.get(c);
symbol[1] = c;
symbol[2] = '\0';
@@ -326,7 +326,7 @@ void expr_t::token_t::next(std::istream& in, const uint_least8_t pflags)
case '>':
in.get(c);
- if (in.peek() == '=') {
+ if (static_cast<char>(in.peek()) == '=') {
in.get(c);
symbol[1] = c;
symbol[2] = '\0';
@@ -387,7 +387,7 @@ void expr_t::token_t::next(std::istream& in, const uint_least8_t pflags)
if (in.fail())
throw_(parse_error, _("Failed to reset input stream"));
- c = in.peek();
+ c = static_cast<char>(in.peek());
if (std::isdigit(c) || c == '.')
expected('\0', c);
@@ -395,12 +395,12 @@ void expr_t::token_t::next(std::istream& in, const uint_least8_t pflags)
} else {
kind = VALUE;
value = temp;
- length = in.tellg() - pos;
+ length = static_cast<std::size_t>(in.tellg() - pos);
}
}
catch (const std::exception& err) {
kind = ERROR;
- length = in.tellg() - pos;
+ length = static_cast<std::size_t>(in.tellg() - pos);
throw;
}
break;
diff --git a/src/utils.h b/src/utils.h
index 86cd56df..323d82b4 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -525,7 +525,7 @@ inline char * skip_ws(char * ptr) {
inline char * trim_ws(char * ptr) {
std::size_t len = std::strlen(ptr);
int i = int(len) - 1;
- while (i >= 0 && ptr[i] == ' ' || ptr[i] == '\t' || ptr[i] == '\n')
+ while (i >= 0 && (ptr[i] == ' ' || ptr[i] == '\t' || ptr[i] == '\n'))
ptr[i--] = '\0';
return skip_ws(ptr);
}
@@ -552,17 +552,17 @@ inline char * next_element(char * buf, bool variable = false) {
}
inline char peek_next_nonws(std::istream& in) {
- char c = in.peek();
+ char c = static_cast<char>(in.peek());
while (in.good() && ! in.eof() && std::isspace(c)) {
in.get(c);
- c = in.peek();
+ c = static_cast<char>(in.peek());
}
return c;
}
#define READ_INTO(str, targ, size, var, cond) { \
char * _p = targ; \
- var = str.peek(); \
+ var = static_cast<char>(str.peek()); \
while (str.good() && ! str.eof() && var != '\n' && \
(cond) && _p - targ < size) { \
str.get(var); \
@@ -574,14 +574,14 @@ inline char peek_next_nonws(std::istream& in) {
break; \
} \
*_p++ = var; \
- var = str.peek(); \
+ var = static_cast<char>(str.peek()); \
} \
*_p = '\0'; \
}
#define READ_INTO_(str, targ, size, var, idx, cond) { \
char * _p = targ; \
- var = str.peek(); \
+ var = static_cast<char>(str.peek()); \
while (str.good() && ! str.eof() && var != '\n' && \
(cond) && _p - targ < size) { \
str.get(var); \
@@ -595,7 +595,7 @@ inline char peek_next_nonws(std::istream& in) {
idx++; \
} \
*_p++ = var; \
- var = str.peek(); \
+ var = static_cast<char>(str.peek()); \
} \
*_p = '\0'; \
}
diff --git a/src/xact.cc b/src/xact.cc
index 0db98c9f..0e5914d1 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -179,11 +179,12 @@ bool xact_base_t::finalize()
post_t * top_post = NULL;
foreach (post_t * post, posts) {
- if (! post->amount.is_null())
+ if (! post->amount.is_null()) {
if (post->amount.is_annotated())
top_post = post;
else if (! top_post)
top_post = post;
+ }
if (post->cost && ! post->has_flags(POST_COST_CALCULATED)) {
saw_cost = true;
diff --git a/test/unit/t_amount.cc b/test/unit/t_amount.cc
index 7f0ae669..05505fda 100644
--- a/test/unit/t_amount.cc
+++ b/test/unit/t_amount.cc
@@ -369,10 +369,10 @@ void AmountTestCase::testCommodityEquality()
assertTrue(x0.is_null());
assertThrow(x0.is_zero(), amount_error);
assertThrow(x0.is_realzero(), amount_error);
- assertThrow(x0.sign() == 0, amount_error);
- assertThrow(x0.compare(x1) < 0, amount_error);
- assertThrow(x0.compare(x2) > 0, amount_error);
- assertThrow(x0.compare(x0) == 0, amount_error);
+ assertThrow(x0.sign(), amount_error);
+ assertThrow(x0.compare(x1), amount_error);
+ assertThrow(x0.compare(x2), amount_error);
+ assertThrow(x0.compare(x0), amount_error);
assertTrue(x1 != x2);
assertTrue(x1 != x4);
@@ -1170,7 +1170,9 @@ void AmountTestCase::testTruth()
amount_t x1("1234");
amount_t x2("1234.56");
- assertThrow(x0 ? 1 : 0, amount_error);
+#ifndef NOT_FOR_PYTHON
+ assertThrow(x0.operator bool(), amount_error);
+#endif // NOT_FOR_PYTHON
assertTrue(x1);
assertTrue(x2);