summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-02-17 15:17:52 -0600
committerJohn Wiegley <johnw@newartisans.com>2012-02-17 15:17:52 -0600
commitc3a9a7d2c584a7651426b3516f4e9991c8063e02 (patch)
tree6a7748588d90d3d9e0032903548b3411d7277dd6 /src
parentc6b51a2635bdf7da803dd2fc8251d6c290f134a4 (diff)
downloadfork-ledger-c3a9a7d2c584a7651426b3516f4e9991c8063e02.tar.gz
fork-ledger-c3a9a7d2c584a7651426b3516f4e9991c8063e02.tar.bz2
fork-ledger-c3a9a7d2c584a7651426b3516f4e9991c8063e02.zip
Fixed many Clang type conversion warnings with static_cast
Diffstat (limited to 'src')
-rw-r--r--src/accum.cc6
-rw-r--r--src/amount.cc12
-rw-r--r--src/commodity.cc4
-rw-r--r--src/filters.cc2
-rw-r--r--src/format.cc12
-rw-r--r--src/format.h2
-rw-r--r--src/item.cc2
-rw-r--r--src/option.cc4
-rw-r--r--src/output.cc31
-rw-r--r--src/post.cc6
-rw-r--r--src/print.cc20
-rw-r--r--src/py_account.cc4
-rw-r--r--src/py_balance.cc4
-rw-r--r--src/py_journal.cc11
-rw-r--r--src/py_xact.cc4
-rw-r--r--src/pyfstream.h4
-rw-r--r--src/report.cc9
-rw-r--r--src/textual.cc23
-rw-r--r--src/unistring.h5
19 files changed, 91 insertions, 74 deletions
diff --git a/src/accum.cc b/src/accum.cc
index 157f459d..8f3d5185 100644
--- a/src/accum.cc
+++ b/src/accum.cc
@@ -39,7 +39,7 @@ std::streamsize straccbuf::xsputn(const char * s, std::streamsize num)
{
if (index == 0) {
// The first item received is the format string
- str = std::string(s, num);
+ str = std::string(s, static_cast<std::string::size_type>(num));
}
else {
std::ostringstream buf;
@@ -53,7 +53,7 @@ std::streamsize straccbuf::xsputn(const char * s, std::streamsize num)
if (*q && *q != '%' && std::isdigit(*q) &&
std::string::size_type(*q - '0') == index) {
p++;
- buf << std::string(s, num);
+ buf << std::string(s, static_cast<std::string::size_type>(num));
matched = true;
} else {
buf << *p;
@@ -63,7 +63,7 @@ std::streamsize straccbuf::xsputn(const char * s, std::streamsize num)
}
}
if (! matched)
- buf << std::string(s, num);
+ buf << std::string(s, static_cast<std::string::size_type>(num));
str = buf.str();
}
diff --git a/src/amount.cc b/src/amount.cc
index 9a84a457..85afc3d8 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -129,7 +129,8 @@ namespace {
// Convert the rational number to a floating-point, extending the
// floating-point to a large enough size to get a precise answer.
- mp_prec_t num_prec = mpz_sizeinbase(mpq_numref(quant), 2);
+ mp_prec_t num_prec =
+ static_cast<mpfr_prec_t>(mpz_sizeinbase(mpq_numref(quant), 2));
num_prec += amount_t::extend_by_digits*64;
if (num_prec < MPFR_PREC_MIN)
num_prec = MPFR_PREC_MIN;
@@ -138,7 +139,8 @@ namespace {
mpfr_set_prec(tempfnum, num_prec);
mpfr_set_z(tempfnum, mpq_numref(quant), rnd);
- mp_prec_t den_prec = mpz_sizeinbase(mpq_denref(quant), 2);
+ mp_prec_t den_prec =
+ static_cast<mpfr_prec_t>(mpz_sizeinbase(mpq_denref(quant), 2));
den_prec += amount_t::extend_by_digits*64;
if (den_prec < MPFR_PREC_MIN)
den_prec = MPFR_PREC_MIN;
@@ -168,9 +170,11 @@ namespace {
}
}
if (point > 0) {
- while (--index >= (point + 1 + zeros_prec) && buf[index] == '0')
+ while (--index >= (point + 1 + static_cast<std::size_t>(zeros_prec)) &&
+ buf[index] == '0')
buf[index] = '\0';
- if (index >= (point + zeros_prec) && buf[index] == '.')
+ if (index >= (point + static_cast<std::size_t>(zeros_prec)) &&
+ buf[index] == '.')
buf[index] = '\0';
}
}
diff --git a/src/commodity.cc b/src/commodity.cc
index 3431a4ee..5fd54d11 100644
--- a/src/commodity.cc
+++ b/src/commodity.cc
@@ -567,7 +567,7 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol)
while (_p - buf < 255 && in.good() && ! in.eof() && c != '\n') {
std::size_t bytes = 0;
std::ptrdiff_t size = _p - buf;
- unsigned char d = c;
+ unsigned char d = static_cast<unsigned char>(c);
// Check for the start of a UTF-8 multi-byte encoded string
if (d >= 192 && d <= 223 && size < 254)
@@ -627,7 +627,7 @@ void commodity_t::parse_symbol(char *& p, string& symbol)
char * q = std::strchr(p + 1, '"');
if (! q)
throw_(amount_error, _("Quoted commodity symbol lacks closing quote"));
- symbol = string(p + 1, 0, q - p - 1);
+ symbol = string(p + 1, 0, static_cast<std::string::size_type>(q - p - 1));
p = q + 2;
} else {
char * q = next_element(p);
diff --git a/src/filters.cc b/src/filters.cc
index 32f42cf4..331073eb 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -171,7 +171,7 @@ namespace {
const char * b = str.c_str();
for (const char * p = b; *p; p++) {
if (*p == ch) {
- strings.push_back(string(b, p - b));
+ strings.push_back(string(b, static_cast<std::string::size_type>(p - b)));
b = p + 1;
}
}
diff --git a/src/format.cc b/src/format.cc
index 4fd9700a..93e7ea08 100644
--- a/src/format.cc
+++ b/src/format.cc
@@ -156,7 +156,7 @@ format_t::element_t * format_t::parse_elements(const string& fmt,
std::size_t num = 0;
while (*p && std::isdigit(*p)) {
num *= 10;
- num += *p++ - '0';
+ num += static_cast<std::size_t>(*p++ - '0');
}
current->min_width = num;
@@ -165,7 +165,7 @@ format_t::element_t * format_t::parse_elements(const string& fmt,
num = 0;
while (*p && std::isdigit(*p)) {
num *= 10;
- num += *p++ - '0';
+ num += static_cast<std::size_t>(*p++ - '0');
}
current->max_width = num;
if (current->min_width == 0)
@@ -188,10 +188,10 @@ format_t::element_t * format_t::parse_elements(const string& fmt,
*p != 'D' && *p != 'E' && *p != 'F'))
throw_(format_error, _("%$ field reference must be a digit from 1-9"));
- unsigned int index = std::isdigit(*p) ? *p - '0' : (*p - 'A' + 10);
- element_t * tmpl_elem = tmpl->elements.get();
+ int index = std::isdigit(*p) ? *p - '0' : (*p - 'A' + 10);
+ element_t * tmpl_elem = tmpl->elements.get();
- for (unsigned int i = 1; i < index && tmpl_elem; i++) {
+ for (int i = 1; i < index && tmpl_elem; i++) {
tmpl_elem = tmpl_elem->next.get();
while (tmpl_elem && tmpl_elem->type != element_t::EXPR)
tmpl_elem = tmpl_elem->next.get();
@@ -335,7 +335,7 @@ string format_t::real_calc(scope_t& scope)
switch (elem->type) {
case element_t::STRING:
if (elem->min_width > 0)
- out.width(elem->min_width);
+ out.width(static_cast<std::streamsize>(elem->min_width));
out << boost::get<string>(elem->data);
break;
diff --git a/src/format.h b/src/format.h
index 256dd66a..f30b8184 100644
--- a/src/format.h
+++ b/src/format.h
@@ -100,7 +100,7 @@ class format_t : public expr_base_t<string>
out << std::right;
if (elem->min_width > 0)
- out.width(elem->min_width);
+ out.width(static_cast<std::streamsize>(elem->min_width));
}
void dump(std::ostream& out) const;
diff --git a/src/item.cc b/src/item.cc
index 026a3790..056aa04c 100644
--- a/src/item.cc
+++ b/src/item.cc
@@ -145,7 +145,7 @@ void item_t::parse_tags(const char * p,
(std::isdigit(*(b + 1)) || *(b + 1) == '=')) {
if (const char * e = std::strchr(p, ']')) {
char buf[256];
- std::strncpy(buf, b + 1, e - b - 1);
+ std::strncpy(buf, b + 1, static_cast<std::size_t>(e - b - 1));
buf[e - b - 1] = '\0';
if (char * pp = std::strchr(buf, '=')) {
diff --git a/src/option.cc b/src/option.cc
index 02ae3040..2843c775 100644
--- a/src/option.cc
+++ b/src/option.cc
@@ -133,7 +133,7 @@ void process_environment(const char ** envp, const string& tag,
if (*q == '=') {
try {
- string value = string(*p, q - *p);
+ string value = string(*p, static_cast<std::string::size_type>(q - *p));
if (! value.empty())
process_option(string("$") + buf, string(buf), scope, q + 1, value);
}
@@ -190,7 +190,7 @@ strings_list process_arguments(strings_list args, scope_t& scope)
const char * value = NULL;
if (const char * p = std::strchr(name, '=')) {
- opt_name = string(name, p - name);
+ opt_name = string(name, static_cast<std::string::size_type>(p - name));
value = ++p;
DEBUG("option.args", " read option value from option: " << value);
} else {
diff --git a/src/output.cc b/src/output.cc
index 9305cd28..b26881a3 100644
--- a/src/output.cc
+++ b/src/output.cc
@@ -52,13 +52,14 @@ format_posts::format_posts(report_t& _report,
const char * f = format.c_str();
if (const char * p = std::strstr(f, "%/")) {
- first_line_format.parse_format(string(f, 0, p - f));
+ first_line_format.parse_format
+ (string(f, 0, static_cast<std::string::size_type>(p - f)));
const char * n = p + 2;
- if (const char * p = std::strstr(n, "%/")) {
- next_lines_format.parse_format(string(n, 0, p - n),
- first_line_format);
- between_format.parse_format(string(p + 2),
- first_line_format);
+ if (const char * pp = std::strstr(n, "%/")) {
+ next_lines_format.parse_format
+ (string(n, 0, static_cast<std::string::size_type>(pp - n)),
+ first_line_format);
+ between_format.parse_format(string(pp + 2), first_line_format);
} else {
next_lines_format.parse_format(string(n), first_line_format);
}
@@ -99,7 +100,7 @@ void format_posts::operator()(post_t& post)
}
if (prepend_format) {
- out.width(prepend_width);
+ out.width(static_cast<std::streamsize>(prepend_width));
out << prepend_format(bound_scope);
}
@@ -135,11 +136,14 @@ format_accounts::format_accounts(report_t& _report,
const char * f = format.c_str();
if (const char * p = std::strstr(f, "%/")) {
- account_line_format.parse_format(string(f, 0, p - f));
+ account_line_format.parse_format
+ (string(f, 0, static_cast<std::string::size_type>(p - f)));
const char * n = p + 2;
- if (const char * p = std::strstr(n, "%/")) {
- total_line_format.parse_format(string(n, 0, p - n), account_line_format);
- separator_format.parse_format(string(p + 2), account_line_format);
+ if (const char * pp = std::strstr(n, "%/")) {
+ total_line_format.parse_format
+ (string(n, 0, static_cast<std::string::size_type>(pp - n)),
+ account_line_format);
+ separator_format.parse_format(string(pp + 2), account_line_format);
} else {
total_line_format.parse_format(n, account_line_format);
}
@@ -181,7 +185,7 @@ std::size_t format_accounts::post_account(account_t& account, const bool flat)
}
if (prepend_format) {
- out.width(prepend_width);
+ out.width(static_cast<std::streamsize>(prepend_width));
out << prepend_format(bound_scope);
}
@@ -256,7 +260,8 @@ void format_accounts::flush()
out << separator_format(bound_scope);
if (prepend_format) {
- static_cast<std::ostream&>(report.output_stream).width(prepend_width);
+ static_cast<std::ostream&>(report.output_stream)
+ .width(static_cast<std::streamsize>(prepend_width));
static_cast<std::ostream&>(report.output_stream)
<< prepend_format(bound_scope);
}
diff --git a/src/post.cc b/src/post.cc
index ed5cd911..b40e31f0 100644
--- a/src/post.cc
+++ b/src/post.cc
@@ -270,9 +270,9 @@ namespace {
if (args.has(0)) {
if (args[0].is_long()) {
if (args.get<long>(0) > 2)
- name = format_t::truncate(account.fullname(),
- args.get<long>(0) - 2,
- 2 /* account_abbrev_length */);
+ name = format_t::truncate
+ (account.fullname(), static_cast<std::size_t>(args.get<long>(0) - 2),
+ /* account_abbrev_length= */ 2);
else
name = account.fullname();
} else {
diff --git a/src/print.cc b/src/print.cc
index ffa4e9eb..b7f72bf0 100644
--- a/src/print.cc
+++ b/src/print.cc
@@ -98,8 +98,9 @@ namespace {
string leader = buf.str();
out << leader;
- std::size_t columns = (report.HANDLED(columns_) ?
- report.HANDLER(columns_).value.to_long() : 80);
+ std::size_t columns =
+ (report.HANDLED(columns_) ?
+ static_cast<std::size_t>(report.HANDLER(columns_).value.to_long()) : 80);
if (xact.note)
print_note(out, *xact.note, columns, unistring(leader).length());
@@ -152,17 +153,18 @@ namespace {
std::size_t account_width =
(report.HANDLER(account_width_).specified ?
- report.HANDLER(account_width_).value.to_long() : 36);
+ static_cast<std::size_t>(report.HANDLER(account_width_).value.to_long()) : 36);
if (account_width < name.length())
account_width = name.length();
if (! post->has_flags(POST_CALCULATED) || report.HANDLED(generated)) {
out << name.extract();
- int slip = (static_cast<int>(account_width) -
- static_cast<int>(name.length()));
+ std::string::size_type slip =
+ (static_cast<std::string::size_type>(account_width) -
+ static_cast<std::string::size_type>(name.length()));
if (slip > 0) {
- out.width(slip);
+ out.width(static_cast<std::streamsize>(slip));
out << ' ';
}
@@ -185,8 +187,10 @@ namespace {
string trimmed_amt(amt);
trim_left(trimmed_amt);
- int amt_slip = (static_cast<int>(amt.length()) -
- static_cast<int>(trimmed_amt.length()));
+ std::string::size_type amt_slip =
+ (static_cast<std::string::size_type>(amt.length()) -
+ static_cast<std::string::size_type>(trimmed_amt.length()));
+
if (slip + amt_slip < 2)
amtbuf << string(2 - (slip + amt_slip), ' ');
amtbuf << amt;
diff --git a/src/py_account.cc b/src/py_account.cc
index 07d6ed95..5ef86871 100644
--- a/src/py_account.cc
+++ b/src/py_account.cc
@@ -44,7 +44,7 @@ namespace {
long accounts_len(account_t& account)
{
- return account.accounts.size();
+ return static_cast<long>(account.accounts.size());
}
account_t& accounts_getitem(account_t& account, long i)
@@ -53,7 +53,7 @@ namespace {
static account_t * last_account = NULL;
static accounts_map::iterator elem;
- long len = account.accounts.size();
+ long len = static_cast<long>(account.accounts.size());
if (labs(i) >= len) {
PyErr_SetString(PyExc_IndexError, _("Index out of range"));
diff --git a/src/py_balance.cc b/src/py_balance.cc
index e86217b5..0140a625 100644
--- a/src/py_balance.cc
+++ b/src/py_balance.cc
@@ -81,11 +81,11 @@ namespace {
#endif
long balance_len(balance_t& bal) {
- return bal.amounts.size();
+ return static_cast<long>(bal.amounts.size());
}
amount_t balance_getitem(balance_t& bal, long i) {
- long len = bal.amounts.size();
+ long len = static_cast<long>(bal.amounts.size());
if (labs(i) >= len) {
PyErr_SetString(PyExc_IndexError, _("Index out of range"));
diff --git a/src/py_journal.cc b/src/py_journal.cc
index 5eac9eb0..bd781225 100644
--- a/src/py_journal.cc
+++ b/src/py_journal.cc
@@ -56,7 +56,7 @@ namespace {
long xacts_len(journal_t& journal)
{
- return journal.xacts.size();
+ return static_cast<long>(journal.xacts.size());
}
#if 0
@@ -66,7 +66,7 @@ namespace {
static journal_t * last_journal = NULL;
static xacts_list::iterator elem;
- long len = journal.xacts.size();
+ long len = static_cast<long>(journal.xacts.size());
if (labs(i) >= len) {
PyErr_SetString(PyExc_IndexError, _("Index out of range"));
@@ -91,7 +91,7 @@ namespace {
long accounts_len(account_t& account)
{
- return account.accounts.size();
+ return static_cast<long>(account.accounts.size());
}
account_t& accounts_getitem(account_t& account, long i)
@@ -100,7 +100,7 @@ namespace {
static account_t * last_account = NULL;
static accounts_map::iterator elem;
- long len = account.accounts.size();
+ long len = static_cast<long>(account.accounts.size());
if (labs(i) >= len) {
PyErr_SetString(PyExc_IndexError, _("Index out of range"));
@@ -210,7 +210,8 @@ namespace {
post_t * posts_getitem(collector_wrapper& collector, long i)
{
- post_t * post = collector.posts_collector->posts[i];
+ post_t * post =
+ collector.posts_collector->posts[static_cast<std::string::size_type>(i)];
std::cerr << typeid(post).name() << std::endl;
std::cerr << typeid(*post).name() << std::endl;
std::cerr << typeid(post->account).name() << std::endl;
diff --git a/src/py_xact.cc b/src/py_xact.cc
index adaf81a2..604d8d59 100644
--- a/src/py_xact.cc
+++ b/src/py_xact.cc
@@ -44,7 +44,7 @@ namespace {
long posts_len(xact_base_t& xact)
{
- return xact.posts.size();
+ return static_cast<long>(xact.posts.size());
}
post_t& posts_getitem(xact_base_t& xact, long i)
@@ -53,7 +53,7 @@ namespace {
static xact_base_t * last_xact = NULL;
static posts_list::iterator elem;
- long len = xact.posts.size();
+ long len = static_cast<long>(xact.posts.size());
if (labs(i) >= len) {
PyErr_SetString(PyExc_IndexError, _("Index out of range"));
diff --git a/src/pyfstream.h b/src/pyfstream.h
index 2fb9e1a7..49b072f2 100644
--- a/src/pyfstream.h
+++ b/src/pyfstream.h
@@ -68,7 +68,7 @@ protected:
// write multiple characters
virtual std::streamsize xsputn (const char* s, std::streamsize num) {
char * buf = new char[num + 1];
- std::strncpy(buf, s, num);
+ std::strncpy(buf, s, static_cast<std::size_t>(num));
buf[num] = '\0';
if (PyFile_WriteString(buf, reinterpret_cast<PyObject *>(fo)) < 0)
num = 0;
@@ -148,7 +148,7 @@ protected:
* - but at most size of putback area
*/
size_t numPutback;
- numPutback = gptr() - eback();
+ numPutback = static_cast<size_t>(gptr() - eback());
if (numPutback > pbSize) {
numPutback = pbSize;
}
diff --git a/src/report.cc b/src/report.cc
index b943fd3e..f4dc450e 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -577,7 +577,7 @@ value_t report_t::fn_trim(call_scope_t& args)
return string_value(empty_string);
}
else {
- return string_value(string(p, e - p));
+ return string_value(string(p, static_cast<std::string::size_type>(e - p)));
}
}
@@ -641,9 +641,10 @@ value_t report_t::fn_truncated(call_scope_t& args)
{
return string_value(format_t::truncate
(args.get<string>(0),
- (args.has<int>(1) &&
- args.get<int>(1) > 0) ? args.get<int>(1) : 0,
- args.has<int>(2) ? args.get<int>(2) : 0));
+ (args.has<int>(1) && args.get<int>(1) > 0) ?
+ static_cast<std::size_t>(args.get<int>(1)) : 0,
+ args.has<int>(2) ?
+ static_cast<std::size_t>(args.get<int>(2)) : 0));
}
value_t report_t::fn_justify(call_scope_t& args)
diff --git a/src/textual.cc b/src/textual.cc
index a11cdebd..c7c49e2a 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -1079,7 +1079,7 @@ post_t * instance_t::parse_post(char * line,
char buf[MAX_LINE + 1];
std::strcpy(buf, line);
- std::size_t beg = 0;
+ std::streamsize beg = 0;
try {
@@ -1135,7 +1135,7 @@ post_t * instance_t::parse_post(char * line,
p++; e--;
}
- string name(p, e - p);
+ string name(p, static_cast<std::string::size_type>(e - p));
DEBUG("textual.parse", "line " << linenum << ": "
<< "Parsed account name " << name);
@@ -1166,8 +1166,8 @@ post_t * instance_t::parse_post(char * line,
// Parse the optional amount
if (next && *next && (*next != ';' && *next != '=')) {
- beg = next - line;
- ptristream stream(next, len - beg);
+ beg = static_cast<std::streamsize>(next - line);
+ ptristream stream(next, static_cast<std::size_t>(len - beg));
if (*next != '(') // indicates a value expression
post->amount.parse(stream, PARSE_NO_REDUCE);
@@ -1223,7 +1223,7 @@ post_t * instance_t::parse_post(char * line,
<< "And it's for a total price");
}
- beg = ++next - line;
+ beg = static_cast<std::streamsize>(++next - line);
p = skip_ws(next);
if (*p) {
@@ -1237,8 +1237,8 @@ post_t * instance_t::parse_post(char * line,
throw parse_error(_("Posting is missing a cost amount"));
}
- beg = p - line;
- ptristream cstream(p, len - beg);
+ beg = static_cast<std::streamsize>(p - line);
+ ptristream cstream(p, static_cast<std::size_t>(len - beg));
if (*p != '(') // indicates a value expression
post->cost->parse(cstream, PARSE_NO_MIGRATE);
@@ -1288,14 +1288,14 @@ post_t * instance_t::parse_post(char * line,
DEBUG("textual.parse", "line " << linenum << ": "
<< "Found a balance assignment indicator");
- beg = ++next - line;
+ beg = static_cast<std::streamsize>(++next - line);
p = skip_ws(next);
if (*p) {
post->assigned_amount = amount_t();
- beg = p - line;
- ptristream stream(p, len - beg);
+ beg = static_cast<std::streamsize>(p - line);
+ ptristream stream(p, static_cast<std::size_t>(len - beg));
if (*p != '(') // indicates a value expression
post->assigned_amount->parse(stream, PARSE_NO_MIGRATE);
@@ -1398,7 +1398,8 @@ post_t * instance_t::parse_post(char * line,
}
catch (const std::exception&) {
add_error_context(_("While parsing posting:"));
- add_error_context(line_context(buf, beg, len));
+ add_error_context(line_context(buf, static_cast<std::string::size_type>(beg),
+ static_cast<std::string::size_type>(len)));
throw;
}
}
diff --git a/src/unistring.h b/src/unistring.h
index 577e0da4..4be36b0d 100644
--- a/src/unistring.h
+++ b/src/unistring.h
@@ -92,8 +92,9 @@ public:
if (this_len)
utf8::unchecked::utf32to8
- (utf32chars.begin() + begin,
- utf32chars.begin() + begin +
+ (utf32chars.begin() + static_cast<std::string::difference_type>(begin),
+ utf32chars.begin() + static_cast<std::string::difference_type>(begin) +
+ static_cast<std::string::difference_type>
(len ? (len > this_len ? this_len : len) : this_len),
std::back_inserter(utf8result));