blob: d3ac55c09d4ff9b262e00638d76ac8f882930a9b [file] [log] [blame]
James Kuszmaulb13e13f2023-11-22 20:44:04 -08001From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Peter Johnson <johnson.peter@gmail.com>
3Date: Sat, 10 Jun 2023 14:13:07 -0700
Maxwell Henderson80bec322024-01-09 15:48:44 -08004Subject: [PATCH 01/12] Fix sign-compare warnings
James Kuszmaulb13e13f2023-11-22 20:44:04 -08005
6---
7 src/google/protobuf/compiler/importer.cc | 2 +-
8 src/google/protobuf/compiler/parser.cc | 4 ++--
9 src/google/protobuf/io/io_win32.cc | 2 +-
10 src/google/protobuf/stubs/stringprintf.cc | 4 ++--
11 src/google/protobuf/stubs/strutil.cc | 2 +-
12 src/google/protobuf/stubs/substitute.cc | 2 +-
13 src/google/protobuf/util/field_mask_util.cc | 2 +-
14 src/google/protobuf/util/internal/datapiece.cc | 7 +++++++
15 .../protobuf/util/internal/default_value_objectwriter.cc | 4 ++--
16 .../protobuf/util/internal/default_value_objectwriter.h | 2 +-
17 src/google/protobuf/util/internal/json_escaping.cc | 6 +++---
18 src/google/protobuf/util/internal/json_objectwriter.h | 2 +-
19 src/google/protobuf/util/internal/json_stream_parser.cc | 8 ++++----
20 src/google/protobuf/util/internal/proto_writer.cc | 2 +-
21 .../protobuf/util/internal/protostream_objectwriter.cc | 2 +-
22 src/google/protobuf/util/internal/utility.cc | 2 +-
23 src/google/protobuf/util/json_util.cc | 2 +-
24 17 files changed, 31 insertions(+), 24 deletions(-)
25
26diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc
27index f1e26f8bdd1d3619acd8827f9a2a0e6b2acdd124..678e87eb03cc3959a1890327cd1e918cb1896fa3 100644
28--- a/src/google/protobuf/compiler/importer.cc
29+++ b/src/google/protobuf/compiler/importer.cc
30@@ -398,7 +398,7 @@ DiskSourceTree::DiskFileToVirtualFile(const std::string& disk_file,
31 int mapping_index = -1;
32 std::string canonical_disk_file = CanonicalizePath(disk_file);
33
34- for (int i = 0; i < mappings_.size(); i++) {
35+ for (size_t i = 0; i < mappings_.size(); i++) {
36 // Apply the mapping in reverse.
37 if (ApplyMapping(canonical_disk_file, mappings_[i].disk_path,
38 mappings_[i].virtual_path, virtual_file)) {
39diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc
40index 5bd37d147bc449444f875f89367a208a32a9146e..e36a4a74359fcace20c017f241d58930660b9381 100644
41--- a/src/google/protobuf/compiler/parser.cc
42+++ b/src/google/protobuf/compiler/parser.cc
43@@ -159,7 +159,7 @@ bool IsLowerUnderscore(const std::string& name) {
44 }
45
46 bool IsNumberFollowUnderscore(const std::string& name) {
47- for (int i = 1; i < name.length(); i++) {
48+ for (size_t i = 1; i < name.length(); i++) {
49 const char c = name[i];
50 if (IsNumber(c) && name[i - 1] == '_') {
51 return true;
52@@ -500,7 +500,7 @@ void Parser::LocationRecorder::AttachComments(
53 if (!trailing->empty()) {
54 location_->mutable_trailing_comments()->swap(*trailing);
55 }
56- for (int i = 0; i < detached_comments->size(); ++i) {
57+ for (size_t i = 0; i < detached_comments->size(); ++i) {
58 location_->add_leading_detached_comments()->swap((*detached_comments)[i]);
59 }
60 detached_comments->clear();
61diff --git a/src/google/protobuf/io/io_win32.cc b/src/google/protobuf/io/io_win32.cc
62index 4e8190880918f1ba155d75db76d6c1ee0b003247..78c07d0d771b9c227c6cd930fc91d272fd67500f 100644
63--- a/src/google/protobuf/io/io_win32.cc
64+++ b/src/google/protobuf/io/io_win32.cc
65@@ -198,7 +198,7 @@ wstring normalize(wstring path) {
66 // Join all segments.
67 bool first = true;
68 std::wstringstream result;
69- for (int i = 0; i < segments.size(); ++i) {
70+ for (size_t i = 0; i < segments.size(); ++i) {
71 if (!first) {
72 result << L'\\';
73 }
74diff --git a/src/google/protobuf/stubs/stringprintf.cc b/src/google/protobuf/stubs/stringprintf.cc
75index a6ad4c0da4080f5241c26176046a3add5247e25c..8b890f47c386f0d6b0ab9fd9928fae03edd076eb 100644
76--- a/src/google/protobuf/stubs/stringprintf.cc
77+++ b/src/google/protobuf/stubs/stringprintf.cc
78@@ -149,10 +149,10 @@ std::string StringPrintfVector(const char* format,
79 // or displaying random chunks of memory to users.
80
81 const char* cstr[kStringPrintfVectorMaxArgs];
82- for (int i = 0; i < v.size(); ++i) {
83+ for (size_t i = 0; i < v.size(); ++i) {
84 cstr[i] = v[i].c_str();
85 }
86- for (int i = v.size(); i < GOOGLE_ARRAYSIZE(cstr); ++i) {
87+ for (size_t i = v.size(); i < GOOGLE_ARRAYSIZE(cstr); ++i) {
88 cstr[i] = &string_printf_empty_block[0];
89 }
90
91diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc
92index 594c8eac6a6ebff6d8bc8cc8518e3fd521f24da1..3462e91ff273dc071628f06b91698a0f166514fc 100644
93--- a/src/google/protobuf/stubs/strutil.cc
94+++ b/src/google/protobuf/stubs/strutil.cc
95@@ -697,7 +697,7 @@ bool safe_parse_positive_int(std::string text, IntType *value_p) {
96 IntType value = 0;
97 const IntType vmax = std::numeric_limits<IntType>::max();
98 assert(vmax > 0);
99- assert(vmax >= base);
100+ assert(static_cast<int>(vmax) >= base);
101 const IntType vmax_over_base = vmax / base;
102 const char* start = text.data();
103 const char* end = start + text.size();
104diff --git a/src/google/protobuf/stubs/substitute.cc b/src/google/protobuf/stubs/substitute.cc
105index d301682ee3377760430839bc5d6530621333e48d..8c75b2562e43d9d4ade3ef187d38e2e81b43e2c7 100644
106--- a/src/google/protobuf/stubs/substitute.cc
107+++ b/src/google/protobuf/stubs/substitute.cc
108@@ -128,7 +128,7 @@ void SubstituteAndAppend(std::string* output, const char* format,
109 }
110 }
111
112- GOOGLE_DCHECK_EQ(target - output->data(), output->size());
113+ GOOGLE_DCHECK_EQ(target - output->data(), static_cast<int>(output->size()));
114 }
115
116 } // namespace strings
117diff --git a/src/google/protobuf/util/field_mask_util.cc b/src/google/protobuf/util/field_mask_util.cc
118index 700e59004a083c731477bcc0bb4d5c36d06f306c..9a40b851a9e51d30b286ff5d89707bf9f279d0c0 100644
119--- a/src/google/protobuf/util/field_mask_util.cc
120+++ b/src/google/protobuf/util/field_mask_util.cc
121@@ -366,7 +366,7 @@ void FieldMaskTree::RemovePath(const std::string& path,
122 Node* node = &root_;
123 const Descriptor* current_descriptor = descriptor;
124 Node* new_branch_node = nullptr;
125- for (int i = 0; i < parts.size(); ++i) {
126+ for (size_t i = 0; i < parts.size(); ++i) {
127 nodes[i] = node;
128 const FieldDescriptor* field_descriptor =
129 current_descriptor->FindFieldByName(parts[i]);
130diff --git a/src/google/protobuf/util/internal/datapiece.cc b/src/google/protobuf/util/internal/datapiece.cc
131index 3e7aa84da7181e2ab270e181b9f63deb1905542f..56f4a18fa4afc64708938fa5352937cdd17b5747 100644
132--- a/src/google/protobuf/util/internal/datapiece.cc
133+++ b/src/google/protobuf/util/internal/datapiece.cc
134@@ -53,6 +53,10 @@ namespace {
135
136 template <typename To, typename From>
137 util::StatusOr<To> ValidateNumberConversion(To after, From before) {
138+#ifdef __GNUC__
139+#pragma GCC diagnostic push
140+#pragma GCC diagnostic ignored "-Wsign-compare"
141+#endif
142 if (after == before &&
143 MathUtil::Sign<From>(before) == MathUtil::Sign<To>(after)) {
144 return after;
145@@ -62,6 +66,9 @@ util::StatusOr<To> ValidateNumberConversion(To after, From before) {
146 : std::is_same<From, double>::value ? DoubleAsString(before)
147 : FloatAsString(before));
148 }
149+#ifdef __GNUC__
150+#pragma GCC diagnostic pop
151+#endif
152 }
153
154 // For general conversion between
155diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.cc b/src/google/protobuf/util/internal/default_value_objectwriter.cc
156index 7f61cdafa7c771a69364c5e9c49667535b16d957..a7d4ce78bd47e0250def474df8937927be9ef116 100644
157--- a/src/google/protobuf/util/internal/default_value_objectwriter.cc
158+++ b/src/google/protobuf/util/internal/default_value_objectwriter.cc
159@@ -312,7 +312,7 @@ void DefaultValueObjectWriter::Node::PopulateChildren(
160 std::unordered_map<std::string, int> orig_children_map;
161
162 // Creates a map of child nodes to speed up lookup.
163- for (int i = 0; i < children_.size(); ++i) {
164+ for (size_t i = 0; i < children_.size(); ++i) {
165 InsertIfNotPresent(&orig_children_map, children_[i]->name_, i);
166 }
167
168@@ -389,7 +389,7 @@ void DefaultValueObjectWriter::Node::PopulateChildren(
169 new_children.push_back(child.release());
170 }
171 // Adds all leftover nodes in children_ to the beginning of new_child.
172- for (int i = 0; i < children_.size(); ++i) {
173+ for (size_t i = 0; i < children_.size(); ++i) {
174 if (children_[i] == nullptr) {
175 continue;
176 }
177diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.h b/src/google/protobuf/util/internal/default_value_objectwriter.h
178index a9e1673fa1e4ed35ab6890a44eed1d362265d914..1a151ab25951f8b0e1c9c724253b16524b88530a 100644
179--- a/src/google/protobuf/util/internal/default_value_objectwriter.h
180+++ b/src/google/protobuf/util/internal/default_value_objectwriter.h
181@@ -154,7 +154,7 @@ class PROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
182 bool preserve_proto_field_names, bool use_ints_for_enums,
183 FieldScrubCallBack field_scrub_callback);
184 virtual ~Node() {
185- for (int i = 0; i < children_.size(); ++i) {
186+ for (size_t i = 0; i < children_.size(); ++i) {
187 delete children_[i];
188 }
189 }
190diff --git a/src/google/protobuf/util/internal/json_escaping.cc b/src/google/protobuf/util/internal/json_escaping.cc
191index e4fa8cf788642e4a9d9c0460c287b1c24891b9fa..c192ddca7aff3984ffcbf82e13585bdf34ad8aae 100644
192--- a/src/google/protobuf/util/internal/json_escaping.cc
193+++ b/src/google/protobuf/util/internal/json_escaping.cc
194@@ -179,7 +179,7 @@ bool ReadCodePoint(StringPiece str, int index, uint32_t* cp,
195 // the last unicode code point.
196 *num_read = 0;
197 }
198- while (*num_left > 0 && index < str.size()) {
199+ while (*num_left > 0 && index < static_cast<int>(str.size())) {
200 uint32_t ch = static_cast<uint8_t>(str[index++]);
201 --(*num_left);
202 ++(*num_read);
203@@ -309,7 +309,7 @@ void JsonEscaping::Escape(strings::ByteSource* input,
204 while (input->Available() > 0) {
205 StringPiece str = input->Peek();
206 StringPiece escaped;
207- int i = 0;
208+ size_t i = 0;
209 int num_read;
210 bool ok;
211 bool cp_was_split = num_left > 0;
212@@ -349,7 +349,7 @@ void JsonEscaping::Escape(StringPiece input, strings::ByteSink* output) {
213 const char* p = input.data();
214
215 bool can_skip_escaping = true;
216- for (int i = 0; i < len; i++) {
217+ for (size_t i = 0; i < len; i++) {
218 char c = p[i];
219 if (c < 0x20 || c >= 0x7F || c == '"' || c == '<' || c == '>' ||
220 c == '\\') {
221diff --git a/src/google/protobuf/util/internal/json_objectwriter.h b/src/google/protobuf/util/internal/json_objectwriter.h
222index cb7dff6e9fe79858a73b2c7501106fe8d05ccac5..92348da3b5c3f07e6146136352f976c94fe54340 100644
223--- a/src/google/protobuf/util/internal/json_objectwriter.h
224+++ b/src/google/protobuf/util/internal/json_objectwriter.h
225@@ -102,7 +102,7 @@ class PROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter {
226 if (!indent_string.empty()) {
227 indent_char_ = indent_string[0];
228 indent_count_ = indent_string.length();
229- for (int i = 1; i < indent_string.length(); i++) {
230+ for (size_t i = 1; i < indent_string.length(); i++) {
231 if (indent_char_ != indent_string_[i]) {
232 indent_char_ = '\0';
233 indent_count_ = 0;
234diff --git a/src/google/protobuf/util/internal/json_stream_parser.cc b/src/google/protobuf/util/internal/json_stream_parser.cc
235index 5c34dbccafb9f40249ba3c0b7318b2e897f203dc..e786781f6de23c8a7ea282d061df6032111f6d21 100644
236--- a/src/google/protobuf/util/internal/json_stream_parser.cc
237+++ b/src/google/protobuf/util/internal/json_stream_parser.cc
238@@ -80,7 +80,7 @@ inline void ReplaceInvalidCodePoints(StringPiece str,
239 const std::string& replacement,
240 std::string* dst) {
241 while (!str.empty()) {
242- int n_valid_bytes = internal::UTF8SpnStructurallyValid(str);
243+ size_t n_valid_bytes = internal::UTF8SpnStructurallyValid(str);
244 StringPiece valid_part = str.substr(0, n_valid_bytes);
245 StrAppend(dst, valid_part);
246
247@@ -98,7 +98,7 @@ inline void ReplaceInvalidCodePoints(StringPiece str,
248
249 static bool ConsumeKey(StringPiece* input, StringPiece* key) {
250 if (input->empty() || !IsLetter((*input)[0])) return false;
251- int len = 1;
252+ size_t len = 1;
253 for (; len < input->size(); ++len) {
254 if (!IsAlphanumeric((*input)[len])) {
255 break;
256@@ -113,7 +113,7 @@ static bool ConsumeKey(StringPiece* input, StringPiece* key) {
257 static bool ConsumeKeyPermissive(StringPiece* input,
258 StringPiece* key) {
259 if (input->empty() || !IsLetter((*input)[0])) return false;
260- int len = 1;
261+ size_t len = 1;
262 for (; len < input->size(); ++len) {
263 if (IsKeySeparator((*input)[len])) {
264 break;
265@@ -946,7 +946,7 @@ util::Status JsonStreamParser::ParseKey() {
266 JsonStreamParser::TokenType JsonStreamParser::GetNextTokenType() {
267 SkipWhitespace();
268
269- int size = p_.size();
270+ size_t size = p_.size();
271 if (size == 0) {
272 // If we ran out of data, report unknown and we'll place the previous parse
273 // type onto the stack and try again when we have more data.
274diff --git a/src/google/protobuf/util/internal/proto_writer.cc b/src/google/protobuf/util/internal/proto_writer.cc
275index afa5e2e474b6960b8826a40b73615d5dffd971de..11b6df13d8f4f9506e828c39d6e74bc8acceb23d 100644
276--- a/src/google/protobuf/util/internal/proto_writer.cc
277+++ b/src/google/protobuf/util/internal/proto_writer.cc
278@@ -408,7 +408,7 @@ std::string ProtoWriter::ProtoElement::ToString() const {
279 if (!ow_->IsRepeated(*(now->parent_field_)) ||
280 now->parent()->parent_field_ != now->parent_field_) {
281 std::string name = now->parent_field_->name();
282- int i = 0;
283+ size_t i = 0;
284 while (i < name.size() &&
285 (ascii_isalnum(name[i]) || name[i] == '_'))
286 ++i;
287diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.cc b/src/google/protobuf/util/internal/protostream_objectwriter.cc
288index ecb219e06e514b1a6ba0e3e343126a75852d0a1d..ce94cfcefb417203f80142c54003efea283f6a1c 100644
289--- a/src/google/protobuf/util/internal/protostream_objectwriter.cc
290+++ b/src/google/protobuf/util/internal/protostream_objectwriter.cc
291@@ -378,7 +378,7 @@ void ProtoStreamObjectWriter::AnyWriter::StartAny(const DataPiece& value) {
292
293 // Now we know the proto type and can interpret all data fields we gathered
294 // before the "@type" field.
295- for (int i = 0; i < uninterpreted_events_.size(); ++i) {
296+ for (size_t i = 0; i < uninterpreted_events_.size(); ++i) {
297 uninterpreted_events_[i].Replay(this);
298 }
299 }
300diff --git a/src/google/protobuf/util/internal/utility.cc b/src/google/protobuf/util/internal/utility.cc
301index 918ee17d9b040ae1bf9d98e3f46f75770c471393..3c4ac086d594d67b334cbc1dc046c281cd59a374 100644
302--- a/src/google/protobuf/util/internal/utility.cc
303+++ b/src/google/protobuf/util/internal/utility.cc
304@@ -345,7 +345,7 @@ void DeleteWellKnownTypes() { delete well_known_types_; }
305
306 void InitWellKnownTypes() {
307 well_known_types_ = new std::set<std::string>;
308- for (int i = 0; i < GOOGLE_ARRAYSIZE(well_known_types_name_array_); ++i) {
309+ for (size_t i = 0; i < GOOGLE_ARRAYSIZE(well_known_types_name_array_); ++i) {
310 well_known_types_->insert(well_known_types_name_array_[i]);
311 }
312 google::protobuf::internal::OnShutdown(&DeleteWellKnownTypes);
313diff --git a/src/google/protobuf/util/json_util.cc b/src/google/protobuf/util/json_util.cc
314index c39c10d87b7d8bf6fc18cae1ce459257c45945d6..a9b1c52a73c86d3e3655ba0748f2a82c68bd40ce 100644
315--- a/src/google/protobuf/util/json_util.cc
316+++ b/src/google/protobuf/util/json_util.cc
317@@ -64,7 +64,7 @@ ZeroCopyStreamByteSink::~ZeroCopyStreamByteSink() {
318
319 void ZeroCopyStreamByteSink::Append(const char* bytes, size_t len) {
320 while (true) {
321- if (len <= buffer_size_) { // NOLINT
322+ if (static_cast<int>(len) <= buffer_size_) { // NOLINT
323 memcpy(buffer_, bytes, len);
324 buffer_ = static_cast<char*>(buffer_) + len;
325 buffer_size_ -= len;