summaryrefslogtreecommitdiff
path: root/src/report.cc
diff options
context:
space:
mode:
authorAlexis Hildebrandt <afh@surryhill.net>2018-01-27 15:55:08 +0800
committerGitHub <noreply@github.com>2018-01-27 15:55:08 +0800
commit1be23f1653724b4e7a197662bc5418c5996b1136 (patch)
tree9082cb9059a01cf380bd7c51f09f1b4aff517d02 /src/report.cc
parentc6c328c011d7e31121a585596833d2dd951302ce (diff)
parent1070c17f8c8933b6b243dbcb5fefabb26e0afcba (diff)
downloadfork-ledger-1be23f1653724b4e7a197662bc5418c5996b1136.tar.gz
fork-ledger-1be23f1653724b4e7a197662bc5418c5996b1136.tar.bz2
fork-ledger-1be23f1653724b4e7a197662bc5418c5996b1136.zip
Merge pull request #521 from mbudde/fix-trim
Fix handling of edge cases in trim function
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 44f0c4b9..cb7f09dc 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 {