summaryrefslogtreecommitdiff
path: root/src/report.cc
diff options
context:
space:
mode:
authorMichael Budde <mbudde@gmail.com>2018-01-25 21:14:10 +0100
committerMichael Budde <mbudde@gmail.com>2018-01-25 21:14:10 +0100
commit1070c17f8c8933b6b243dbcb5fefabb26e0afcba (patch)
tree88f02bb41f76f2d4af17fa8d914015afc93b83fc /src/report.cc
parentb3b72cbea23a69bcbf7a30ca34471c72c07370e4 (diff)
downloadfork-ledger-1070c17f8c8933b6b243dbcb5fefabb26e0afcba.tar.gz
fork-ledger-1070c17f8c8933b6b243dbcb5fefabb26e0afcba.tar.bz2
fork-ledger-1070c17f8c8933b6b243dbcb5fefabb26e0afcba.zip
Fix handling of edge cases in trim function
Fixes #520
Diffstat (limited to 'src/report.cc')
-rw-r--r--src/report.cc11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/report.cc b/src/report.cc
index 2f3cc302..856cb523 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -633,18 +633,15 @@ value_t report_t::fn_trim(call_scope_t& args)
std::strcpy(buf.get(), temp.c_str());
const char * p = buf.get();
- while (*p && std::isspace(*p))
+ const char * e = buf.get() + temp.length() - 1;
+
+ while (p <= e && std::isspace(*p))
p++;
- const char * e = buf.get() + temp.length() - 1;
while (e > p && std::isspace(*e))
e--;
- if (e == p) {
- return string_value(empty_string);
- }
- else if (e < p) {
- assert(false);
+ if (p > e) {
return string_value(empty_string);
}
else {