aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-04-08 21:24:57 +0200
committerAdrian Kummerlaender2016-04-08 21:24:57 +0200
commitee09160000d99cd90e7c7137600c2f0e0087f991 (patch)
tree212c797e2a8a1962f08b876f216f54287be412d2 /src
parent8ccbf252e3d3910081de920b2388204e425400c0 (diff)
downloadjustify-ee09160000d99cd90e7c7137600c2f0e0087f991.tar
justify-ee09160000d99cd90e7c7137600c2f0e0087f991.tar.gz
justify-ee09160000d99cd90e7c7137600c2f0e0087f991.tar.bz2
justify-ee09160000d99cd90e7c7137600c2f0e0087f991.tar.lz
justify-ee09160000d99cd90e7c7137600c2f0e0087f991.tar.xz
justify-ee09160000d99cd90e7c7137600c2f0e0087f991.tar.zst
justify-ee09160000d99cd90e7c7137600c2f0e0087f991.zip
Prevent negative result of substraction of unsigned lengths
Furthermore `LineAccumulator::getMissing` returning 0 if the line is longer than the maximum length is what its name implies.
Diffstat (limited to 'src')
-rw-r--r--src/line_accumulator.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/line_accumulator.cc b/src/line_accumulator.cc
index 31b8ddc..4398c50 100644
--- a/src/line_accumulator.cc
+++ b/src/line_accumulator.cc
@@ -68,20 +68,24 @@ LineAccumulator::~LineAccumulator() {
}
std::uint8_t LineAccumulator::getMissing() const {
- return this->max_length_ - this->length_;
+ if ( this->length_ < this->max_length_ ) {
+ return this->max_length_ - this->length_;
+ } else {
+ return 0;
+ }
}
void LineAccumulator::operator()(const std::string& token) {
const std::size_t tokenLength = getCharacterLength(token);
- if ( ( this->length_ + tokenLength ) > this->max_length_ ) {
+ if ( tokenLength > this->getMissing() ) {
this->discharge(true);
}
this->tokens_.emplace_back(token, 0);
this->length_ += tokenLength;
- if ( this->length_ < this->max_length_ ) {
+ if ( this->getMissing() > 0 ) {
this->tokens_.back().second += 1;
this->length_ += 1;
}