Skip to content

Commit de8b411

Browse files
committed
compiler: Fix some warnings when building with Bazel
This fixes sign-compare and maybe-unintialized. An unused-value warning remains. I changed LogHelper to always call abort so the compiler would know the method does not return, which fixed the maxbe-uninitialized warning.
1 parent db9b7ed commit de8b411

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

compiler/src/java_plugin/cpp/java_generator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static inline string MessageFullJavaName(bool nano, const Descriptor* desc) {
8787
// No java package specified.
8888
return "nano." + name;
8989
}
90-
for (int i = 0; i < name.size(); ++i) {
90+
for (size_t i = 0; i < name.size(); ++i) {
9191
if ((name[i] == '.') && (i < (name.size() - 1)) && isupper(name[i + 1])) {
9292
return name.substr(0, i + 1) + "nano." + name.substr(i + 1);
9393
}
@@ -251,7 +251,7 @@ static void GrpcWriteDocCommentBody(Printer* printer,
251251
printer->Print(" * <pre>\n");
252252
}
253253

254-
for (int i = 0; i < lines.size(); i++) {
254+
for (size_t i = 0; i < lines.size(); i++) {
255255
// Most lines should start with a space. Watch out for lines that start
256256
// with a /, since putting that right after the leading asterisk will
257257
// close the comment.
@@ -781,7 +781,7 @@ static void PrintMethodHandlerClass(const ServiceDescriptor* service,
781781
}
782782
stable_sort(sorted_methods.begin(), sorted_methods.end(),
783783
CompareMethodClientStreaming);
784-
for (int i = 0; i < sorted_methods.size(); i++) {
784+
for (size_t i = 0; i < sorted_methods.size(); i++) {
785785
const MethodDescriptor* method = sorted_methods[i];
786786
(*vars)["method_id"] = to_string(i);
787787
(*vars)["method_id_name"] = MethodIdFieldName(method);

compiler/src/java_plugin/cpp/java_generator.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@
1010

1111
class LogHelper {
1212
std::ostream* os;
13-
bool abort;
1413

1514
public:
16-
LogHelper(std::ostream* os, bool abort) : os(os), abort(abort) {}
15+
LogHelper(std::ostream* os) : os(os) {}
1716
~LogHelper() {
1817
*os << std::endl;
19-
if (abort) {
20-
::abort();
21-
}
18+
::abort();
2219
}
2320
std::ostream& get_os() {
2421
return *os;
@@ -27,7 +24,7 @@ class LogHelper {
2724

2825
// Abort the program after logging the mesage if the given condition is not
2926
// true. Otherwise, do nothing.
30-
#define GRPC_CODEGEN_CHECK(x) !(x) && LogHelper(&std::cerr, true).get_os() \
27+
#define GRPC_CODEGEN_CHECK(x) !(x) && LogHelper(&std::cerr).get_os() \
3128
<< "CHECK FAILED: " << __FILE__ << ":" \
3229
<< __LINE__ << ": "
3330

compiler/src/java_plugin/cpp/java_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
3838
java_grpc_generator::ProtoFlavor::NORMAL;
3939

4040
bool enable_deprecated = false;
41-
for (int i = 0; i < options.size(); i++) {
41+
for (size_t i = 0; i < options.size(); i++) {
4242
if (options[i].first == "nano") {
4343
flavor = java_grpc_generator::ProtoFlavor::NANO;
4444
} else if (options[i].first == "lite") {

0 commit comments

Comments
 (0)