Skip to content

Commit 0e1a1fc

Browse files
committed
Validator: Fix compiler warnings (signed/unsigned)
This also fixes a regression in validate_grapheme_test introduced by commit 32e9d7c. Signed-off-by: Stefan Weil <[email protected]>
1 parent f5a7ca2 commit 0e1a1fc

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

src/training/validate_indic.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ bool ValidateIndic::ConsumeViramaIfValid(IndicPair joiner, bool post_matra) {
120120
ASSERT_HOST(!CodeOnlyToOutput());
121121
} else {
122122
// Half-form with optional Nukta.
123-
int len = output_.size() + 1 - output_used_;
123+
unsigned len = output_.size() + 1 - output_used_;
124124
if (UseMultiCode(len)) return true;
125125
}
126126
if (codes_used_ < num_codes &&
@@ -179,7 +179,7 @@ bool ValidateIndic::ConsumeConsonantHeadIfValid() {
179179
CodeOnlyToOutput();
180180
// Special Sinhala case of [H Z Yayana/Rayana].
181181
int index = output_.size() - 3;
182-
if (output_used_ <= index &&
182+
if (output_used_ + 3 <= output_.size() &&
183183
(output_.back() == kYayana || output_.back() == kRayana) &&
184184
IsVirama(output_[index]) && output_[index + 1] == kZeroWidthJoiner) {
185185
MultiCodePart(3);
@@ -192,7 +192,7 @@ bool ValidateIndic::ConsumeConsonantHeadIfValid() {
192192
}
193193
// Test for subscript conjunct.
194194
index = output_.size() - 2 - have_nukta;
195-
if (output_used_ <= index && IsSubscriptScript() &&
195+
if (output_used_ + 2 + have_nukta <= output_.size() && IsSubscriptScript() &&
196196
IsVirama(output_[index])) {
197197
// Output previous virama, consonant + optional nukta.
198198
MultiCodePart(2 + have_nukta);

src/training/validate_javanese.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* File: validate_javanese.cpp
33
* Description: Text validator for Javanese Script - aksara jawa.
44
* Author: Shree Devi Kumar
5-
* Created: August 03, 2018
65
*
76
* Licensed under the Apache License, Version 2.0 (the "License");
87
* you may not use this file except in compliance with the License.
@@ -90,7 +89,7 @@ bool ValidateJavanese::ConsumeViramaIfValid(IndicPair joiner, bool post_matra) {
9089
ASSERT_HOST(!CodeOnlyToOutput());
9190
} else {
9291
// Half-form with optional Nukta.
93-
int len = output_.size() + 1 - output_used_;
92+
unsigned len = output_.size() + 1 - output_used_;
9493
if (UseMultiCode(len)) return true;
9594
}
9695
if (codes_used_ < num_codes &&
@@ -149,7 +148,7 @@ bool ValidateJavanese::ConsumeConsonantHeadIfValid() {
149148
CodeOnlyToOutput();
150149
// Special Sinhala case of [H Z Yayana/Rayana].
151150
int index = output_.size() - 3;
152-
if (output_used_ <= index &&
151+
if (output_used_ + 3 <= output_.size() &&
153152
(output_.back() == kPengkal || output_.back() == kCakra) &&
154153
IsVirama(output_[index]) && output_[index + 1] == kZeroWidthJoiner) {
155154
MultiCodePart(3);
@@ -162,7 +161,7 @@ bool ValidateJavanese::ConsumeConsonantHeadIfValid() {
162161
}
163162
// Test for subscript conjunct.
164163
index = output_.size() - 2 - have_nukta;
165-
if (output_used_ <= index && IsSubscriptScript() &&
164+
if (output_used_ + 2 + have_nukta <= output_.size() && IsSubscriptScript() &&
166165
IsVirama(output_[index])) {
167166
// Output previous virama, consonant + optional nukta.
168167
MultiCodePart(2 + have_nukta);

src/training/validate_khmer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool ValidateKhmer::ConsumeGraphemeIfValid() {
4545
if (UseMultiCode(1)) return true;
4646
}
4747
}
48-
int num_matra_parts = 0;
48+
unsigned num_matra_parts = 0;
4949
if (codes_[codes_used_].second == kZeroWidthJoiner ||
5050
codes_[codes_used_].second == kZeroWidthNonJoiner) {
5151
if (CodeOnlyToOutput()) {

src/training/validator.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Description: Base class for various text validators. Intended mainly for
44
* scripts that use a virama character.
55
* Author: Ray Smith
6-
* Created: Tue May 23 2017
76
*
87
* (C) Copyright 2017, Google Inc.
98
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -179,7 +178,7 @@ class Validator {
179178
// output_, adds unicodes as single-element vectors to parts_ to catch
180179
// output_used_ up to output->size() - length before adding the length-element
181180
// vector.
182-
void MultiCodePart(int length) {
181+
void MultiCodePart(unsigned length) {
183182
while (output_used_ + length < output_.size()) {
184183
parts_.emplace_back(
185184
std::initializer_list<char32>{output_[output_used_++]});
@@ -193,7 +192,7 @@ class Validator {
193192
// Helper function appends the next element of codes_ to output_, and then
194193
// calls MultiCodePart to add the appropriate components to parts_.
195194
// Returns true at the end of codes_.
196-
bool UseMultiCode(int length) {
195+
bool UseMultiCode(unsigned length) {
197196
output_.push_back(codes_[codes_used_].second);
198197
MultiCodePart(length);
199198
return ++codes_used_ == codes_.size();

0 commit comments

Comments
 (0)